Question on printf()

Doug Gwyn gwyn at smoke.BRL.MIL
Sat Jun 16 05:17:06 AEST 1990


In article <1990Jun15.042610.18292 at dasys1.uucp> jpr at dasys1.UUCP (Jean-Pierre Radley) writes:
>>3. add a setbuf(stdout,(char *) 0) at the begining of your program.  This 
>>turns off all output buffering and can have a detrimental effect on the
>>overall performance of your software.  
>Why is that?

Because it turns off buffering on the stdout stream!
I suppose your real question is, what is buffering good for.
By buffering several sequential putchar()s (or equivalent)
in a data area belonging to the C library stdio implementation
(linked into your application), and performing a system call
to write out the entire buffer just once when the buffer fills
up (or, in some circumstances, whenever a new-line character
is seen), instead of a system call per character as must be
done when buffering is disabled, obviously the number of
system calls to transfer the same amount of data is
drastically reduced. Since there is considerable overhead
involved in making a system call, minimimizing the number of
system calls made leads to better application performance.



More information about the Comp.unix.questions mailing list