Re: FIFO File writing
From: Kirsten (stefanklauer_at_gmx.de)
Date: 08/26/04
- Next message: PeP: "Re: a hint for this"
- Previous message: TLOlczyk: "Re: Are / Were you a Siebel Software Engineer?"
- In reply to: CBFalconer: "Re: FIFO File writing"
- Next in thread: Willem: "Re: FIFO File writing"
- Reply: Willem: "Re: FIFO File writing"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 26 Aug 2004 10:23:28 +0200
Thanks for your good suggestion!
I think that the point of your anser is: "You cannot make FIFO files"!
I've thought about your answer and came to the conclusion: good, but not what I really want:
- exclusive write access prevents reading the file while debugging
- the file is hard to read (always seek to the first line and then goto the current pos)
"CBFalconer" <cbfalconer@yahoo.com> schrieb im Newsbeitrag news:412D5219.727A1DC8@yahoo.com...
> Kirsten wrote:
> >
> > This night I searched the whole internet... and I cannot believe
> > that there is no possibility the write to a file "first in -
> > first out"? Well, how to implement a file logging system? How to
> > implement history file writer?
> >
> > I want to add a new line at the end of my log file, after that
> > the first line should deleted, so my file cannot get bigger and
> > bigger. Working in memory this data structure would be called
> > queue. But I want/need it for files (immediate physical saving).
>
> First, fix your line length. I had to reformat the above. Your
> lines should not exceed 78 chars ever, and 65 is much better.
>
> Create a file of fixed length records. Reserve the zeroth record
> to show the current write pointer, which will always be pointing
> at the oldest record. To read the file, read record 0, seek the
> appropriate record, read from there to the end, and from record 1
> up to the initial record.
>
> To write a new record, read the 0th, form the pointer, seek there
> and write the new record. Then seek the 0th and write back
> whatever you represent the current pointer (incremented) by.
>
> The easiest way would be to make all those records simply strings
> of ASCII chars. But you will want to put them in and out with
> binary operations, i.e. this is a binary file.
>
> The file is vulnerable between writing the new record and writing
> the 0th index record, so you probably need to open it with
> exclusive write access. You might be able to inhibit any readers
> by first writing an invalid marker to the index record, but watch
> out for recovery from crashes.
>
> Figure out the initialization for yourself.
>
> --
> Chuck F (cbfalconer@yahoo.com) (cbfalconer@worldnet.att.net)
> Available for consulting/temporary embedded and systems.
> <http://cbfalconer.home.att.net> USE worldnet address!
>
>
- Next message: PeP: "Re: a hint for this"
- Previous message: TLOlczyk: "Re: Are / Were you a Siebel Software Engineer?"
- In reply to: CBFalconer: "Re: FIFO File writing"
- Next in thread: Willem: "Re: FIFO File writing"
- Reply: Willem: "Re: FIFO File writing"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|