Path: utzoo!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!pasteur!ames!pacbell!pbhyf!rob From: rob@pbhyf.PacBell.COM (Rob Bernardo) Newsgroups: comp.unix.questions Subject: Re: C/UNIX low level I/O Keywords: C, I/O, open, fopen Message-ID: <4150@pbhyf.PacBell.COM> Date: 2 Nov 88 16:37:34 GMT References: <6695@pyr.gatech.EDU> Reply-To: rob@pbhyf.PacBell.COM (Rob Bernardo) Organization: Pacific * Bell, San Ramon, CA Lines: 30 In article <6695@pyr.gatech.EDU> david@pyr.gatech.edu (David Brown) writes: + I need to do a bunch of + small write's to a file. I need to know the quickest way to do it. ... + 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. Like this: + + while (list ~empty){ + write word + write space + } + write newline + + My question: is there a better way to do this? I've thought of using + higher-level I/O routines like fprintf, but I think they would be + less efficient. But less efficient than what I'm doing now? Use fputs() to write the strings (your "word") and fputc() to write the single characters (your "space" and "newline"). Fprintf() is overkill because you don't have any formatting of the output to perform. Using these stdio functions instead of the system call write() is more efficient insofar as these functions buffer the writes, i.e. generally they store what is to be written until a whole block is to be written, and then they call write() to write whole blocks at a time. (WARNING: that's a simplification.) -- Rob Bernardo, Pacific Bell UNIX/C Reusable Code Library Email: ...![backbone]!pacbell!pbhyf!rob OR rob@pbhyf.PacBell.COM Office: (415) 823-2417 Room 4E750A, San Ramon Valley Administrative Center Residence: (415) 827-4301 R Bar JB, Concord, California