🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #430

Re: Using WriteFile to write to the start of a file

#430
From: DreamChaser
Date: Sat, 12 Apr 2008 18:41
35 lines
2577 bytes
Mike Collins wrote:
> Hi all, feel a little embarrassed to as such a seemingly easy question 
> but...
> 
> I'm trying to create an event logging system.  I have a main thread that 
> monitors certain things and I need to log these in a text based event log. 
> Because the file i/o make take some time, I've created a new thread to do 
> the actual writing operations.  The main thread pushes events onto the 
> secondary threads stl stack.  The secondary thread should then process these 
> events in a FIFO order and write them to the event log.  So far i think my 
> logic is sound :-).
I thought std::stack was a LIFO. (But you knew that)
> 
<snip>
> appending them. but i can't find anyway to write to the start of 
> the file.  Any suggestions.
See below :)
> 
> Thirdly, I need to ensure that the event log does not exceed a certain size. 
Is "size", File size or number of entries?

> In either of the above cases (writing at the start or writing at the end) 
> how would i approach the problem of removing an entry from my event log.  I 
> would ideally like to perform a check to see if the log has exceeded a 
> certain size and then delete the oldest entry.
I am not all that familiar with the STL, but maybe a VCL option might 
point you in the right direction.

I would use a TSringList in your tread. There is an Insert method that 
you could use to put an entery at the top. Every so often (Timer()) see 
how many items are in the list, truncate the to X length, then 
SaveToFile() to save the whole list in one shot. SaveToFile is fairly quick.

Just some thoughts
DC
Technical Details
Message-ID: <48010255$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!news.isoc.lu!newsgroups.borland.com!not-for-mail
References: <479b78fd@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,265009ffb540730e
X-Google-Attributes: gid10cc67,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Sat, 12 Apr 2008 13:41:25 -0500
From: DreamChaser <NO-Spam@No-Span.net>
User-Agent: Thunderbird 2.0.0.12 (Windows/20080213)
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: Using WriteFile to write to the start of a file
References: <479b78fd@newsgroups.borland.com>
In-Reply-To: <479b78fd@newsgroups.borland.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 65.6.192.60
Message-ID: <48010255$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1208025685 65.6.192.60 (12 Apr 2008 11:41:25 -0700)
Lines: 35
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!news.isoc.lu!newsgroups.borland.com!not-for-mail