Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to change BOF in a file

0 views
Skip to first unread message

Dan F. Rodriguez

unread,
Jan 10, 2000, 3:00:00 AM1/10/00
to
I have a log tha i want to treat as a FIFO and limit its size to a maximumn
number of records. How can I adjust the begining of file pointer to discard
the first bytes of the file? Right now the only way I can do this is by
copying all the records to a temp file except what I want to delete. But
there most be a more efficient way to do this..

John A. Grant

unread,
Jan 10, 2000, 3:00:00 AM1/10/00
to
Dan F. Rodriguez wrote in message ...
This has nothing to do with Windows programming and
nothing to do with your VC++ compiler.

You can manage the file by having 2 pointers - one that
points to the last record written and one that points
to the first record in the sequence. Note that you must use
fixed length-records, otherwise if you over-write a 'short'
record with a longer record, it will over-write part of the
next record.

You can store your 2 pointers in the registry or in an
auxiliary data file.

When you want to read the sequence of records:
- position to the first record
- read all records until EOF
- start at the beginning and read up to the first record

When you write the next record, you do this:
- get the pointer to the last record written
- advance the pointer
- if it points past the maximum file length, reset to 0
- write the record (it might be new, extending the
file size or it might be over-writing an older record)
- if you just over-wrote the 'first record', increment the
'first record' too (wrap to 0 if required)
- update both pointers (registry)

You'll note that none of this requires you to re-write the
file, truncate it or delete records. It will grow from 0 to
a maximum size, then it will remain the same size as new
records continue to over-write older records in the file.

--
John A. Grant * I speak only for myself * (remove 'z' to reply)
Radiation Geophysics, Geological Survey of Canada, Ottawa
If you followup, please do NOT e-mail me a copy: I will read it here

Dan F. Rodriguez

unread,
Jan 10, 2000, 3:00:00 AM1/10/00
to
Sorry,
I forgot to mention this is for a rpogram written using Visual C++

Thanks

Dan F. Rodriguez <d...@iby2.com> wrote in message
news:s7jocev...@corp.supernews.com...

0 new messages