C/UNIX low level I/O

mark mr at homxb.UUCP
Thu Nov 3 05:10:48 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. 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?

You could make a buffer, say 512 chars. Fill the buffer and then
'write' the entire buffer out. (as long as this is not an interactive
application). If you want you can use 'sprintf(3)' to compile a
string which would then be attached to the buffer with strcat or
your own routine.

# Thanks,
#  David Brown

mark
homxb!mr



More information about the Comp.unix.questions mailing list