reducing file size after I am done with an mmap

Is there some way to downsize a file? More specifically, if I open a filebuff: f( "foo.txt",std::ios_base::in|std::ios_base::out|std::ios_base::trunc|std::ios_base::binary); then space forward, write a character, f.pubseekoff( 10000, std::ios_base::beg); write a character, f.sputc(0); f.pubsync(); Is there someway for me to "unwrite the character", and reduce the file size? I am in a situation where I am allocating big files for mmap's, and then when I am done, I have a lot of unused space which I would like to release.

On 18/12/2010 11:12 AM, Clark Sims wrote:
Is there some way to downsize a file?
In unix land: #include <unistd.h> int ftruncate(int fildes, off_t length); int truncate(const char *path, off_t length); Another way is to seek to the offset then writ a block of zero length. In windows land: SetEndOfFile() (I think.....)
participants (2)
-
Arash Partow
-
Clark Sims