file streams

Discussion in 'C Programming' started by Bill Cunningham, May 17, 2014.

  1. Is there any benefit to using any of the buffering functions when
    reading and writing to disk? For example setlinebuf(). I understand by
    default file streams are read as blocks. Does line buffering add any
    benefits for certain situations? And what are these "unlocking" versions of
    stream functions in the stdio library?

    Bill
     
    Bill Cunningham, May 17, 2014
    #1
    1. Advertisements

  2. Bill Cunningham

    Siri Crews Guest

    Potentially there's a disk read for every block with a partial write, and a disk
    write for each full or partial write. Ideally the kernel, if any, is bufferring
    blocks and does the minimal disk activity. If the system has a privileged state
    kernel, it needs a context switch everytime a write is called in the kernel.
    Unbufferred or line bufferred reduces the risk of losing partial output if the
    program aborts. It can increase the time spent in context switches and disk I/O.
     
    Siri Crews, May 17, 2014
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.