#: 3976 S3/Languages
30-May-90 01:14:12
Sb: #C file buffering
Fm: Bob van der Poel 76510,2203
To: all
Here's my next "dumb" question. It has to do with the way 'C' buffers files. If
I understand things correctly all the "proper" file stuff (fopen, fputs, etc.)
use buffered i/o. Of course, this presents problems for terminal i/o. For
example, if you wish to print a line without a CR; or if you use functions like
CurXY()...
This problem can be overcome by using setbuff() so that the i/o is done on a
un-buffered basis. But then, if you want to print a long line it will be done
with a whole series of system calls. I think this would really slow things down
if there was to be a lot of terminal i/o.
So, is there a way to get the best of both worlds. Would something like this
work:
leave file as buffered,
if doing cursor pos, etc. flush the file,
if printing a line with a CR, flush the file,
Or is this needlessly complex. Also, what happens if you just want to get 1 or
2 characters from the keyboard. Will fflush() work here too?
Seems that the simplest thing to do is to forget about buffered files
completely and handle it using the unix-like functions. But the more I read the
more I think this is not the 'best" solution.
So, what thoughts do you have on this...
There are 3 Replies.
|