Path: utzoo!attcan!uunet!mcvax!kth!sunic!maxim!prc From: prc@erbe.se (Robert Claeson) Newsgroups: comp.sources.games.bugs Subject: Re: What setbuf() is and why you should use it Keywords: curses fflush setbuf stdio Message-ID: <763@maxim.erbe.se> Date: 19 Jul 89 07:58:05 GMT References: <283@wet.UUCP> Reply-To: rclaeson@erbe.se (Robert Claeson) Organization: Bonzo Fan Club Lines: 34 In article <283@wet.UUCP> epsilon@wet.UUCP (Eric P. Scott) writes: >The fix is very simple: >put > setbuf(stdout, malloc(BUFSIZ)); >early in main(), and (if you've done any output) > fflush(stdout); >before asking for terminal input, sleeping, going heavily >compute-bound, changing tty modes, or using fork/exec/system-type >calls. This causes stdio to store up to BUFSIZ (defined in >) characters before demanding a context switch. Since >BUFSIZ is typically 512 or 1024, this can be a substantial >improvement. Or, on at least System V-type systems, use the call: #define BUFFER_SIZE 32768 setvbuf(stdout, malloc(BUFFER_SIZE), _IOFBF, BUFFER_SIZE); which can buffer much more than the setbuf() construct above. The buffer can be of arbitrary size. i n e w s -- Robert Claeson E-mail: rclaeson@erbe.se ERBE DATA AB