How to get printf to call write(2) only once?
Dave Sherman
dave at utcsrgv.UUCP
Sat Apr 7 06:26:52 AEST 1984
In running benchmarks on a particular computer to simulate our CAI
application, I seem to have run into a bottleneck in the terminal I/O,
specifically the O. This is a modified version 7 system (Perkin-Elmer
Edition VII Workbench).
It seems to me that a call to printf should trigger a single call
to write, but that's not happening. I looked at the stdio source on
our PDP-11 v7 system, and this is what happens:
1. printf calls _doprnt
2. _doprnt calls _strout on the whole string
3. _strout calls the putc macro
4. since _cnt is 0 (on a terminal line), flsbuf is
called immediately
5. flsbuf calls write on one character.
Now, I realize I can use setbuf to buffer stdout, but I don't want
buffered output. I simply want to reduce the number of character
interrupts generated per printf.
I suppose I can do:
myprintf(a,b,c,d)
{
printf(a,b,c,d);
fflush(stdout);
}
and run setbuf on stdout, but that's (a) kludgey and (b) not guaranteed
to pass the args to printf properly on any particular machine.
Any suggestions? Could _strout be modified to set a flag that _flsbuf
looks at, so that only one call to write(2) is done? Has someone done
this already?
Thanks.
Dave Sherman
The Law Society of Upper Canada
Toronto
--
{allegra,cornell,decvax,ihnp4,linus,utzoo}!utcsrgv!dave
More information about the Comp.unix
mailing list