Reserving Space on Disk

Chris Calabrese[mav] cjc at ulysses.att.com
Tue Jul 17 00:38:46 AEST 1990


In article <MOSS.90Jul15190502 at ibis.cs.umass.edu>, moss at cs.umass.edu (Eliot Moss) writes:
> [ ... ]
> 
> char buf[ONE_K];
> int i;
> 
> for (i = 0; i < FOUR_K; ++i)
>   write (fd, buf, ONE_K);
> [ ... ]

BTW, while reading the various ways to write some large space on the
disk which have been passing by, I thought I'd pass a related tidbit
along.  On many machine architectures, byte copying from user space to
kernel space is quite a bit faster if the buffer is word aligned.

For this reason, it is better to use malloc to get your buffer than to
allocate it off of the stack (as malloc always returns maximally
aligned memory).  Of course, this assumes that you'll use the buffer
more than once, as the time to malloc() is around the same order as
the time to deal with the non-aligned bytes at the beginning and end
of the buffer.
Name:			Christopher J. Calabrese
Brain loaned to:	AT&T Bell Laboratories, Murray Hill, NJ
att!ulysses!cjc		cjc at ulysses.att.com
Obligatory Quote:	``pher - gr. vb. to schlep.  phospher - to schlep light.philosopher - to schlep thoughts.''



More information about the Comp.unix.wizards mailing list