Path: utzoo!attcan!uunet!ingr!crossgl From: crossgl@ingr.UUCP (Gordon Cross) Newsgroups: comp.unix.questions Subject: Re: C/UNIX low level I/O Summary: fill a buffer and do small numbers of large writes... Keywords: C, I/O, open, fopen Message-ID: <2807@ingr.UUCP> Date: 2 Nov 88 15:01:19 GMT References: <6695@pyr.gatech.EDU> Organization: Intergraph Corp. Huntsville, Al Lines: 23 In article <6695@pyr.gatech.EDU>, david@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