Thread: Buffered I/O subsystem

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    2

    Buffered I/O subsystem

    My project requires me to have a function that intializes the system so that it is setup and ready to go with the correct number of buffers being applied. The problem comes from the fact that it requires me to set the stdout and stderr buffers to be set a certain size my problem is that I don't know if I am supposed to just create an unsigned integer value that represents the buffer size or whether I have to some method that is specific to the I/O streams I was curious if anyone knows whether or not there are specific I/O methods that deal with setting buffers for the stdout and stderr streams.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Code:
    static char stdout_buf[N];
    static char stderr_buf[N];
    
    int main ( void )
    {
      ...
    
      /* Before doing anything else with stdout and stderr */
      setvbuf ( stdout, stdout_buf, _IOFBF, N );
      setvbuf ( seterr, stderr_buf, _IOFBF, N );
    
      ...
    }
    The mode options are:

    _IOFBF - Full buffering
    _IOLBF - Line buffering
    _IONBF - unbuffered

    I think you can figure out the others, if not, check you reference manual. setvbuf is in stdio.h.
    My best code is written with the delete key.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Well you can use the setvbuf() call to change the buffering of a stream.

    But I'd leave stderr alone. It's unbuffered by default, so that error messages are not lost in a buffer if the program crashes between reporting the error and finally printing the error.
    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. Buffered/UnBuffered I/O
    By valaris in forum C Programming
    Replies: 1
    Last Post: 08-06-2008, 11:31 PM
  2. asynchronized I/O == multiplexing I/O?
    By George2 in forum C Programming
    Replies: 1
    Last Post: 07-24-2006, 10:06 AM
  3. why page based I/O can improve performance?
    By George2 in forum C Programming
    Replies: 1
    Last Post: 06-12-2006, 07:42 AM
  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