[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#535695: std::ifstream uses a block size of 8191 bytes (not 8192)



Package: libstdc++6-4.3-dev
Version: 4.3.3-13

The program below reads the input file in blocks of 8191 bytes (as
shown by strace).  There's probably a mistake somewhere because it
should use 8192 byte blocks.  (8191 byte blocks tend to maximize
misalignment.)

Recompiling with g++-4.4 doesn't change this.  Using the
in.rdbuf()->sgetc() and friends exhibits the same behavior, too.

#include <iostream>
#include <fstream>

static int usage(const char* progname);

int
main(int argc, const char** argv)
{
  if (argc != 2) {
    return usage(argv[0]);
  }

  const char* filename = argv[1];
  std::ifstream in(filename);

  std::string l;
  while (in) {
    std::getline(in, l);
  }

  if (in.eof()) {
    return 0;
  } else {
    std::cerr << "error: reading from: " << filename << std::endl;
    return 1;
  }
}

static int
usage(const char* progname)
{
  std::cerr << "usage: " << progname << " FILE\n";
  return 1;
}




Reply to: