C/UNIX low level I/O
Gordon Cross
crossgl at ingr.UUCP
Thu Nov 3 01:01:19 AEST 1988
In article <6695 at pyr.gatech.EDU>, david at pyr.gatech.EDU (David Brown) writes:
>
> Hi, NetLanders. I've a small C/UNIX problem. I need to do a bunch of
> small write's to a file. I need to know the quickest way to do it.
> I've got a linked list of 'words' that I need written to a file in a
> humanly readable and understandable fashion. But it needs to take as
> little time as possible. For instance, the way I have it now, I use
> write(2). But this ay, I do a separate 'write' for every word in the
> list, and a 'write' for the spaces between and the newlines.
I've had some experience doing a similiar thing myself. I acheived a
significant increase in throughput by filling a memory buffer with the image
of the data I wished to write out and then doing a single write(2) for the
whole buffer. The reason this is faster is that each call to write(2) requires
a process context switch to the kernal to service the request. The disk
controller itself can slow you down if it is called on repeatedly to do small
operations. I could rant on and on about why this is the case but you should
have the general idea. Also your buffer should be at least the size of a
disk block or multiple thereof. Good luck!
Gordon Cross
Intergraph Corp. Huntsville, AL
More information about the Comp.unix.questions
mailing list