deletion technique?
05-Nov-94 18:41:06
Sb: #43728-deletion technique?
Fm: Steve Ahlstrom 76703,2006
To: Henry Williams 73527,1446
Henry,
You're basically between a rock and a hard place, and, this is a common
programming problem. I'll tell you how'd I'd handle it and hopefully others
will jump in their solutions.
If your file will never be too large to fit into memory, I would create a
linked list of your records and as any record changes, write the list back out
to disk. That's the easy way.
Otherwise you'll have to do what you suggested … hit the records directly
(hopefully you've defined a non-public field called "deleted" or some such) and
set that record to deleted or NULL or whatever you want to use. This will
effectively get rid of the record but it's still in the file. You'll have to
write some routine (external program or part of your main program) to do clean
up on your master file and get rid of the deletes (read a record, if not
deleted, write it to a new file, repeat). The advantage to this is that when
you do clean up your file you can have a chance to again look over the deletes
and recover any if you need to.
-sja