Saturday, November 22, 2014

Controlling Buffering in Standard IO

There are 3 types of buffering

Unbuffer - no user buffering is performed.  Data is written to kernel.  This option is rarely used except for stderr

Line-buffered - the buffer is submit to kernel upon every newline character in the stream.  This is default for stdout (screen).

Block-buffered (Full buffering) - data is buffered in form of block.  This is the default for file.

The type of buffering is specified via the setvbuf() call.  The 3 buffering types are specified as _IONBF, _IOLBF and _IOFBF respectively.  The call must be issued after opening a stream and before performing the first IO.  The caller must also supply the buffer to be managed by Standard IO

Typically application seldom need to manipulate the buffering mode or default buffer size.

No comments: