- Buffereing
Three types of buffereing provided:
- Fully buffered. Files residing on disk are normally fully buffered by the standard I/O library.
- Line buffered. Line buffering is typically used on a system when it refers to a terminal: standard input and standard output.
- Unbuffered. It makes the data output as soon as possible. The standard error stream, for example, is normally unbuffered. This is so that any error messages are displayed as quickly as possible.
void setbuf(FILE * fp, char * buf);
void setvbuf(FILE * fp, char * buf, int mode, size_t size);
- With setbuf, we can turn buffering on or off. To enable buffering, buf must point to a buffer of length BUFSIZ. To disable buffering, we set buf to NULL.
- With setvbuf, We specify exactuly which type of buffering we want. This is done with the mode argument: _IOFBUF -> fully buffered, _IOLBUF -> line buffered, _IONBUF -> unbuffered. The size argument equal the length of the buf.
- In general, we should let the system choose the bufer size and automatically all