Thanks Grant.
The files wont be kept "OPEN" they are really only for logging info, i.e.
errors and events etc.
I figure that I WILL make the records as deleted, and I have already decided
to have a comaction routien to tidy up these records.

Thanks,

Jeremy Coulter 
Application Developer

Application Development Centre
Compaq Computer New Zealand Ltd.

Phone:          64 3 371 5724 (DD)
Fax:                    64 3 371 5744
Cell:                    021 2150435
E-mail:              [EMAIL PROTECTED]
Private E-Mail:  [EMAIL PROTECTED]


-----Original Message-----
From: Grant Black [mailto:[EMAIL PROTECTED]]
Sent: Monday, July 05, 1999 15:09
To: Multiple recipients of list delphi
Subject: RE: [DUG]: Deleteing from a Binary file


> the record might be say 15 or so records into the database.
> is there any easyway to delete this record?
> I thought about doing something like having a wee flag at the 
> begining of the record that says if the record is deleted or not.
> But the problem with this is, that the file size is still 
> going to grow, when if a record is deleted, then the file should
decrease in size.
> the only wqay I can think of doing this is, to copy everything around
the
> record to a new file, then deleteing the old one, and renaming the new
one
> to the old files name....but this seems cumbersom.

What you are describing is exactly the problem faced by any designer of
a file system or database - ie imagine that your records in a single
file are instead files on disk volume. 
As such there is a fairly extensive body of information on how to best
solve the problem - you get to cover this in depth on Operating Systems
part of a ComSci degree. You may want to try doing a search on the net -
take a look a source code for handling B-Trees etc as well.

Anyway, assuming fixed sized records, the easiest way is to mark your
records as Deleted. As you write new records you write over the Deleted
records - hence your file does not continue to grow as you re-use space.
If you have variable sized records or want to get more sophisticated
then you will have to write some garbage collection functions or look at
breaking down the file into chunks.  If you had a 1Gb file you don't
really want to go makeing a copy & of the whole thing when simply delete
a 1K record at the beginning of your master file.  Use also want to
think about want happens if you get a power outage or crash during the
delete process - I have seen a few DB's that die horribly (ie corrupt)
if something goes wrong during write/delete/compact functions, (I won't
even mention any names)

Regards,
Grant  

Grant Black
Software Developer
SmartMove (NZ) Ltd
Phone:     +64 9 361-0219 extn 719
Fax  :     +64 9 361-0211
Email:     [EMAIL PROTECTED]
---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

Jeremy Coulter.vcf

Reply via email to