Re: Update file

new topic     » goto parent     » topic index » view thread      » older message » newer message

Ad Rienks writes:
> From your example I deduce that in update mode a line can be replaced,
> but only if the new line is exactly the same length as the old one. Is this
> the only way to work in update mode? Is it for instance not possible to
> insert a line in between other lines?

There's no easy way to insert a line. Actually, your file doesn't have
to be made up of lines. You could have any kind of data in it.

> I know it is possible to append lines at the end of a file, but for that
> purpose you also have the append mode.
> Personally when I update a file, I first read them into (a) sequence(s),
> close the file and after updating I open the file again for writing.
> Maybe this is more time-consuming, but when time is not that important,
> at the beginning and end of a program.....

I agree. For small to medium sized files, it's simpler to just read the
whole file into memory, manipulate it as a bunch of sequences,
and then write out the new version. That's what ed.ex and
demo\mydata.ex do.

Where update mode and seek() and where() would be crucial,
would be in the case of a huge database. Suppose you had
a 100 Mb file and you wanted to update record # N
in the middle of it. It would be very time consuming to have to
read all the records up to record N and write them out to a new file,
then write out a new record N, then read and write records N+1
to the end. If you had a small index file showing where each record
in the big file started, you could quickly seek to any record and
update it.

To make insertion of records practical, real databases are
not implemented as contiguous records in a
huge file, like my example above, but rather as "B-trees" or equivalent,
with indexes that point to small fixed-size pages of contiguous disk space
that
might contain at most a few hundred consecutive records. Inserting a record
into a
4Kb page that's only half full, by shifting a bunch of other records, is quite
reasonable.
Inserting into a 100Mb file would be very painful.

Regards,
   Rob Craig
   Rapid Deployment Software

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu