deletion technique?
08-Nov-94 16:26:06
Sb: #43728-deletion technique?
Fm: Peter Wade 100265,2740
To: Henry Williams 73527,1446
The best method depends on how you are using the file.
Your method of resaving the file from the deleted record to the end will
work but if the file is long, (or medium size and on a floppy disc) it is
likely to be slow. A compromise method is to remember which records have
been deleted and do the rewrite once when the file is closed, but this is
more complex to program since you have to keep track of 'holes' in the
sequence of records before the file is saved.
Another method is to have a flag on each record which says whether the
record is used. To delete a record simple set it to 'not used'. Your
routines for accessing records will have to check if the flags are set.
When adding a new record don't go straight to the end of the file but
first look for a record set to 'not used'. This makes data access a bit
more tricky, and if the file grows large at any time it will never get
smaller again just from deleting records.
Peter Wade
Autopiloting from London, England