Thread: About setvbuf function

  1. #1
    Registered User
    Join Date
    Sep 2011
    Location
    Athens , Greece
    Posts
    357

    About setvbuf function

    Hello to all .. according to this example

    setvbuf - C++ Reference

    In this example, a file called myfile.txt is created and a full buffer of 1024 bytes is requested for the associated stream, so the data output to this stream should only be written to the file each time the 1024-byte buffer is filled.

    I am trying to understand ... which is the data output? stream is the connection between program and the file myfile.txt?

    thank you in advance

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    The quote you are referencing is saying that the data will not be written to the file until either the buffer is full or you flush the stream.

    Jim

  3. #3
    Registered User
    Join Date
    Sep 2011
    Location
    Athens , Greece
    Posts
    357
    flush the stream with fflush function ok. But I am trying to imagine the scheme. Data comes to the file through the stream and the buffer is something temporary in the physical memory (RAM for example)

    In addition buffer is "flushed" when the file is closed I think
    Last edited by Mr.Lnx; 08-24-2014 at 10:13 AM.

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    First the buffer is part of the stream. It is an array of characters of a fixed size. The size of the buffer and/or the "mode" of the buffer is what you are changing with setvbuf(). A buffer is nothing more than an array of char of a fixed size, this size can be from 0 character to the maximum allowable value of a size_t.


    Jim

  5. #5
    Registered User
    Join Date
    Sep 2011
    Location
    Athens , Greece
    Posts
    357
    Ok buffer is a region of memory. I try to understand what a stream really is and what is the basic difference with a file

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function Prototype, Function Call, and Function definition
    By dmcarpenter in forum C Programming
    Replies: 9
    Last Post: 04-09-2013, 03:29 AM
  2. problem setvbuf
    By vin_pll in forum C Programming
    Replies: 2
    Last Post: 08-10-2009, 11:58 PM
  3. help me understand setvbuf function
    By sick in forum C Programming
    Replies: 2
    Last Post: 11-27-2008, 09:42 AM
  4. Problem about setvbuf()
    By albert3721 in forum C Programming
    Replies: 8
    Last Post: 05-17-2007, 10:02 AM
  5. Replies: 9
    Last Post: 01-02-2007, 04:22 PM