Thread: Buffered/UnBuffered I/O

  1. #1
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    RING 0

    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.


  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. asynchronized I/O == multiplexing I/O?
    By George2 in forum C Programming
    Replies: 1
    Last Post: 07-24-2006, 10:06 AM
  2. why page based I/O can improve performance?
    By George2 in forum C Programming
    Replies: 1
    Last Post: 06-12-2006, 07:42 AM
  3. Nonblocking I/O
    By fnoyan in forum Linux Programming
    Replies: 4
    Last Post: 11-29-2005, 04:37 PM
  4. Overlapped I/O and Completion Port :: Winsock
    By kuphryn in forum Windows Programming
    Replies: 0
    Last Post: 10-30-2002, 05:14 PM
  5. WSAAsyncSelect I/O Mode :: Winsock
    By kuphryn in forum Windows Programming
    Replies: 1
    Last Post: 05-12-2002, 03:23 PM