Buffered/UnBuffered I/O

This is a discussion on Buffered/UnBuffered I/O within the C Programming forums, part of the General Programming Boards category; I ended up checking out the Advanced programming in the UNIX environment after reading the K&R book and it's going ...

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

    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.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,334
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 03:37 PM
  4. Overlapped I/O and Completion Port :: Winsock
    By kuphryn in forum Windows Programming
    Replies: 0
    Last Post: 10-30-2002, 04:14 PM
  5. WSAAsyncSelect I/O Mode :: Winsock
    By kuphryn in forum Windows Programming
    Replies: 1
    Last Post: 05-12-2002, 03:23 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21