Path: utzoo!attcan!uunet!aplcen!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.unix.questions Subject: Re: Question on printf() Message-ID: <13132@smoke.BRL.MIL> Date: 15 Jun 90 19:17:06 GMT References: <24674.266e3b81@kuhub.cc.ukans.edu> <1990Jun8.030206.4532@virtech.uucp> <1990Jun15.042610.18292@dasys1.uucp> Organization: U.S. Army Ballistic Research Laboratory, APG, MD. Lines: 19 In article <1990Jun15.042610.18292@dasys1.uucp> jpr@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.