-
Buffered/UnBuffered I/O
I ended up checking out the Advanced programming in the UNIX environment after reading the K&R book and it's going good. The problem I'm having understanding is the difference between buffered and unbuffered I/O. Stevens really only said that the only difference is unbuffered I/O is a call to the kernel. Does this mean that unbuffered I/O comes directly from memory to your program whereas buffered I/O does what?
If anybody has a clarification on what these terms are or any differences I'd appreciate it.
Cheers.
-
Buffered I/O also calls the kernel, just not EVERY time (hence it's buffered in the C run-time library). Storing a few extra bytes in local memory is better than invoking a context switch into the OS.
stdout is buffered (usually) for efficiency.
stderr is unbuffered (usually) for safety.
If you're sending stuff to stderr, there's some chance you may be crashing, so it's vital that the error message makes it out of the program as quickly as possible.