[comp.unix.questions] How to flush output

chris@mimsy.umd.edu (Chris Torek) (12/09/89)

In article <333@charyb.COM> dan@charyb.COM (Dan Mick) writes:
>fflush()?  You've gotta do that more than once.  Why not add a 
>setbuf(stdout, NULL) to the top of the file?  Quick, easy, simple.

... and slow.  I mean *really* slow.  I mean, really truly HORRIBLY
slow.  I mean, if you think the city buses are slow. . . .

Why not, instead, add a `setvbuf(stdout, (char *)NULL, _IOFBF)' to
main, and then (since tty output will no longer be line buffered, being
efficient instead) add fflush() calls whenever you want the output to
be visible?  I have done it; it is not hard; it makes programs that
produce much output go much faster.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris@cs.umd.edu	Path:	uunet!mimsy!chris

dan@charyb.COM (Dan Mick) (12/10/89)

In article <21184@mimsy.umd.edu> chris@mimsy.umd.edu (Chris Torek) writes:

(about using setbuf(stdout, NULL)

>... and slow.  I mean *really* slow.  I mean, really truly HORRIBLY
>slow.  I mean, if you think the city buses are slow. . . .

Yes, you're absolutely right.  I'd thought he was looking for output whilst
debugging; I don't have any idea how I got that notion locked in my head.
Sorry.  Of course it's horribly inefficient.

While debugging, I don't care, and it involves virtually no source mods, 
so it's far easier to stick in as a temporary change.  But you wouldn't wanna
do it for a finished program.

Sorry for the confusion.  Some humility probably doesn't hurt me, anyway.
-- 
.sig files are idiotic and wasteful.