another c++ i/o questions

Discussion in 'C++' started by Doug Harvey, Aug 26, 2005.

  1. Doug Harvey

    Doug Harvey Guest

    I have a question that hopefully someone here has already figured out

    I have more experience programming in "C", and in order to improve I/
    throughput we would use setvbuf() to increase the buffer size tha
    fread/read used when reading files. It made a pretty big difference
    I tried the following

    char mybuffer[1000000]
    inp.rdbuf()->pubsetbuf(mybuffer,1000000)

    while (getline((inp),line))
    ..

    but it changed the output, seemed like it no longer read all of th
    data
    Any thoughts on the above would be appreciated

    Also, is the read() function the proper way to read fixed-length record
    using the C++ i/o libraries
    Thanks in advance of course

    dou

    --
     
    Doug Harvey, Aug 26, 2005
    #1
    1. Advertising

  2. Doug Harvey wrote:
    > I have a question that hopefully someone here has already figured out.
    >
    > I have more experience programming in "C", and in order to improve I/O
    > throughput we would use setvbuf() to increase the buffer size that
    > fread/read used when reading files. It made a pretty big difference.
    > I tried the following:
    >
    > char mybuffer[1000000];
    > inp.rdbuf()->pubsetbuf(mybuffer,1000000);
    >
    > while (getline((inp),line)) {
    > ...
    >
    > but it changed the output,


    In what way? What was the output before and what is it after? "Changed"
    isn't much to work on.

    > seemed like it no longer read all of the
    > data.


    How much of the data does it read? 10%? 90%? 99.9%? What's missing?

    > Any thoughts on the above would be appreciated.


    From the archives: pubsetbuf does not guaranteed to turn buffering on.
    See this: http://tinyurl.com/7a9a6 (I searched for 'pubsetbuf')

    >
    > Also, is the read() function the proper way to read fixed-length records
    > using the C++ i/o libraries?


    Sure.

    Perhaps you could be a good sport and read the FAQ first. Perhaps after
    that you would consider following the recommendation of FAQ 5.8...

    V
     
    Victor Bazarov, Aug 26, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ali Syed
    Replies:
    3
    Views:
    581
    Mark McIntyre
    Oct 13, 2004
  2. pkirk25
    Replies:
    50
    Views:
    1,163
    Bill Pursell
    Oct 4, 2006
  3. Replies:
    10
    Views:
    580
  4. Vijay
    Replies:
    2
    Views:
    657
    Öö Tiib
    May 7, 2010
  5. reema
    Replies:
    0
    Views:
    309
    reema
    Aug 26, 2008
Loading...

Share This Page