[lkml]   [1997]   [Feb]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: B*gg*r mallocs, mmap JOY!
John Carter <> writes:

> On Mon, 17 Feb 1997, Michael Weller wrote:
> > I agree and was quite surprised about this usage of ftruncate. What you
> > need to do is simply create an empty file of length <n> when you want to
> > mmap <n> bytes. From my knowledge THE standard way to do so is:
> >
> > fseek(fd, <n>, SEEK_SET);
> >
> > fflush(fd); /* probably not needed, fseek does that. */
> >
> > mmap(... fileno(fd) ...);
> Hokay Folks.....
> From the "info glibc" on the subject of fseek....
> INFO> You can move the stream's file position with `fseek' (*note File
> INFO> Positioning::.). Moving the file position past the end of the
> INFO> data already written fills the intervening space with zeroes.
> Note that ftruncate does it instananeously. It isn't wasting my time
> scribbling zero's to disk when I'm about to scribble lots of more
> interesting things directly thereafter. (It takes a looong time to
> scribble 400MB of zero's and to then immediately fill it with
> satellite image. I know. Yawn. Too well. How about a cup of coffee? Has

If you're using a filesystem that allows sparse ("holey") files (such
as ext2fs), fseek() is the conventional way to create them. If you
seek past the end of a file, any full blocks between the end of the
file and the position you sought take up no disk space; the inode
stores a special number where the blocks' locations would normally go.
The zeroes are only written to disk on filesystems that don't allow
sparse files.

Aaron M. Ucko ( | For Geek Code, PGP public key, and other info,
finger | "Kids! Bringing about Armageddon can be dangerous.
Do not attempt it in your home." -- T. Pratchett & N. Gaiman, _Good Omens_

 \ /
  Last update: 2005-03-22 13:38    [W:0.094 / U:5.904 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site