Delete record in Random access file

  • Thread starter Thread starter Andy.I
  • Start date Start date
A

Andy.I

Hi

I have a small aplication that stores data in a random access file. I'm able
to modify records, and add new records. But how can I delete a certain
record and remove it enirely from the file?

/A.
 
Andy.I said:
Hi

I have a small aplication that stores data in a random access file. I'm
able to modify records, and add new records. But how can I delete a
certain record and remove it enirely from the file?

/A.

A quick and easy solution would be to "flag" it as deleted, but leave it in
the file. You then have another procedure that removes all deleted items in
one go every now and then or simply overwrites a "deleted" slot when you add
new records (i.e. the file always grows). There is no way to selectively
"remove" some chunk of data in the middle of a file. You have to copy up to
the point of deletion and append data after the point of deletion into a new
file. Think about a database like SQL Server, it has a "shrink" method and
it will re-use unallocated space, but the file only ever gets bigger unless
you actually tell it to shrink. Deleting records simply returns them to the
pool of usuable space.

I'm not sure about the context of all of this, or whether you can modify
your scheme significantly so it's difficult to state with any more certainty
a better approach.
 
Back
Top