performance of stdio

olson at fortune.UUCP olson at fortune.UUCP
Tue Apr 10 04:38:28 AEST 1984


From: olson (Dave Olson)
What is happenening is that for V7 systems, stdout and stderr were
unbuffered if output is to a terminal.  This eliminated the need for 
fflush() when prompting, etc.  It was, as you have discovered, a real
loss in terms of throughput.  Berkeley made some minor mods to
_flsbuf(), so that stderr is still unbuffered, but stdout is line
buffered.  (Some versions also call fflush(stdout) whenever a
getc(stdin) (or any variants thereof) is done.  Other versions do not.
For those versions, you have to explictly call fflush() when you are
prompting for input without doing a newline. If you are reading input
in any other way than from stdin, you will also have to do an
fflush().)

Buffering can be forced for any stream by doing
setbuf(stream, buffer), and then calling fflush() at the critical
points.  Buffering can also be turned off completely
for any stream, with setbuf(stream, NULL).

Note that the above discussion applies to TERMINAL output only.
stdout is default buffered in BUFSIZ chunks when output is to a pipe,
file, etc.  stderr is default unbuffered under all circumstances.

	Hope this helps,
	Dave Olson, Fortune Systems
	UUCP: {ihnp4,ucbvax!amd70}!fortune!olson
	ARPA: amd70!fortune!olson at BERKELEY

PS: Fortune Systems stdio is based on the Berkeley version, stdout is
line-buffered to a terminal.



More information about the Comp.unix mailing list