Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

inserting into the middle of a file

Status
Not open for further replies.

Sherak

Programmer
Sep 1, 2003
83
GB
If you want to insert a char in the middle of a file do you have to copy the file into memory add the new item at the required point, then re-write the file?... I cant see this as I can imagine some database files are far larger than the local machines system memory so appending or adding a record in the database would be impossible...

I would appriciate any help (or links) on this matter...

Thanks in adv....
 
Well, to insert datas in the middel of a file really means to copy the first part (before new datas) into a new file, then write the new datas into that same new file and then copy the rest of the old file.

After that the old file is deleted and the new is renamed to the old name.

The copying does not need to be a certain size at a time, it is fully possible to do a read-write-read-write-read-write (and so forth) until the desired amounth is transferred.

I'm no database expert but a database _could_ be made such that there is a tabel with pointers and the data in a certain format. This enabled you to "insert" datas into the middel by adding the datas itself to the end of the datafile (or indeed some free space in that file) and just adjust the pointers to show "take 10123 bytes starting at xxx, then (new datas) 1187 bytes starting at yyy, then 27000 bytes starting at zzz, that's all".

This will with time be complex to use, a lot of indexing and such but during the night a program can "defragment" it and thus speed it up.

It's actually very similar to the FAT used on disks (FAT = File Allocation System) and we do defragment it now and then (well, we should at least).

Totte
 
Ahhhhh read/write/read/write yeah I see now Doh!, plus the FAT method is also somthing I'd overlooked, thanks man, My brain needed a bit of a kick start this morning and thanks to you its now turning over :-D given me somthing to think about... My boss wants a smallish database so I think I may stick with the read write but I think I may pour a little time into a FAT class over the next few weeks..

Mucho Appriciato....
 
I'm no database expert either, but I think that some of them put the database into memory, and changes must be committed (i.e. saved to file) before they get saved. That way, moving things in memory is fast. I could be wrong though, just seems like I read that somewhere.

Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top