How do I remove a part of a file efficiently?
Say I have a 10MB file and I need to delete a 2MB chunk of the file from the middle of the file (say at offset 5MB), can this be done without using much memory?
This is how I would like to do it :
- Seek to the offset (at 5MB)
- magically delete the next 2MB and appending the last 3MB.
Im guessing I would need to use some kind of unlink re-addressing function, does this exist in VC?
The slow-and-only way I know of doing it (a hassle with a file exceeding the systems memory) is..
- Seek to offset 7MB
- read the last 3MB into memory
- Seek to offset 5MB
- Write the 3MB and close the file.
Downloads: ZeroOne Realm
May 10, 2001 07:10 PM
Another way you could do it is to read/write upto the end of the 5meg part into another file, skip 2 meg using seek, and write the other 3 meg to the file...then replace the old with the new.
GodBallz
GodBallz
Seek to after the data your going to remove, copy the rest into a temp file..then, truncate the file to remove the data and bring back the data from the other file
I was trying to avoid using temporary files but I guess its the only way to do it without using loads of memory.
Ill try it and see how it goes.
Ill try it and see how it goes.
Downloads: ZeroOne Realm
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement