Re: [Q] large flat files usage
Re: [Q] large flat files usage
- Subject: Re: [Q] large flat files usage
- From: Martin Reed <email@hidden>
- Date: Fri, 21 Jun 2002 09:45:45 +0100
On 21/6/02 1:46 am, "Phillip Morelock" <email@hidden>
wrote:
>
The only thing now that I am having trouble wrapping my head around is
>
writing in the middle of the file. Say, you insert two rows at (say) lines
>
3 and 4 in a 20000000 line file...., "pushing" the rest of the file down.
>
>
Is this in fact what physically happens? Does the (OS/filesystem) have to
>
shove everything over to make room, like when you "insert" an element in the
>
middle of a memory array (where you actually have to copy each of the
>
remaining elements)? If so, an expensive and seemingly unpractical
>
operation when it comes to inserting a 50-byte record in a 20Mbyte file. Or
>
is there something I'm missing conceptually? Sure feels like it!
No. There is no concept of insert for a normal file such as you are planning
to work with. You will either overwrite existing data or possibly extend the
length of the file. A full blown database program (Oracle, mySQL etc) has to
cope with the same behaviour, which is part of the "fun" of writing them.
If:
- you have an index in to your data ie offsets to records
- you have very few updates
- you don't mind the file getting a bit bigger
then a very simple approach is just to write new records to the end of the
file and update the index. Occasionally you'll probably want to compact the
data file by copying it minus the gaps to a new file (and updating the index
to match). This has the useful side-effect of keeping old records around for
a while "just in case".
Mind you, if your needs get even a little bit more complicated I'd switch to
one of the several free relational databases out there :-)
Cheers
martin
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.