title: How to increase buffer size of ofstream
body: <p>I wanted to increase the buffer size of a c++ program so that it does not write too frequently. The default buffer is 8192 bytes, I tried to increase it to 200K with pubsetbuf.</p>
  
  <p>The original code</p>
  
  <pre><code>ofstream fq(fastq1.cstr(), ios::out); // fastq1 is a file
  BamReader reader;  // BamReader parses and reads in "bamFile" below
  reader.Open(bamFile);
  while (reader.GetNext()) {
      fq &lt;&lt; bam.Name &lt;&lt; "\n";
      fq &lt;&lt; bam.seq &lt;&lt; "\n";
      fq &lt;&lt; bam.qual &lt;&lt; "\n";
  }
  </code></pre>
  
  <p>Modified </p>
  
  <pre><code>ofstream fq(fastq1.cstr(), ios::out); // fastq1 is a file with certain format
  // setting buffer size to 200K
  int buf_size = 204800;
  char buf[buf_size];
  fq.rdbuf()-&gt;pubsetbuf(buf, buf_size);
  
  BamReader reader;  // BamReader parses and reads in "bamFile" below
  reader.Open(bamFile);
  while (reader.GetNext()) {
      fq &lt;&lt; bam.Name &lt;&lt; "\n";
      fq &lt;&lt; bam.seq &lt;&lt; "\n";
      fq &lt;&lt; bam.qual &lt;&lt; "\n";
  }
  </code></pre>
  
  <p>However from the strace output it does not seem to make a difference before and after the change.</p>
  
  <pre><code>writev(3, [{"\n@C3A7DACXX140502:3:1209:20544:1"..., 8186}, {"ACCTCCTCCTGCTTTCACCTATCCCGCTTCAC"..., 76}], 2) = 8262
  writev(4, [{"\n@C3A7DACXX140502:3:1209:20544:1"..., 8186}, {"GATCCTCGTCAGTCCTGAAGGAGTGTCAGCTT"..., 76}], 2) = 8262
  writev(3, [{"\n+\nBA@CDEEEDEFEDBBDCDBDBCDCB@DDB"..., 8148}, {"??&gt;ABEEECADDBBABBDCEBDCDCBECDBC@"..., 76}], 2) = 8224
  writev(4, [{"\n+\n&gt;&gt;;ABCD@BEDFCDCDECCECCE?DADCE"..., 8148}, {"&gt;&gt;;ABABBDDECEDECECCCECBBECCDDDFD"..., 76}], 2) = 8224
  writev(3, [{"\n@C3A7DACXX140502:3:1209:20618:6"..., 8184}, {"TTGGAAGGCCAGGTCCAGTAACCGGCCCCATT"..., 76}], 2) = 8260
  writev(4, [{"\n@C3A7DACXX140502:3:1209:20618:6"..., 8184}, {"ATTAGTAATTTCAGTGCCTCCTCCATCTTTAG"..., 76}], 2) = 8260
  writev(3, [{"\n+\n?@&gt;CCDFEEDDDCBDBDEBBCDB@CDBBB"..., 8148}, {"B@&lt;DDDDFCEDEBBDDBDBDC@EBBECDDCEC"..., 76}], 2) = 8224
  writev(4, [{"\n+\n&gt;=;?C@?CBCCEDEAEDCDDBDDBDCDEB"..., 8148}, {"&gt;&gt;&lt;A@BED@DDBDECBCBECCECDBDCDBEED"..., 76}], 2) = 8224
  writev(3, [{"\n@C3A7DACXX140502:3:1209:20684:3"..., 8180}, {"ACCCAAATGAGATCTGTGTGCCAATGTCAGTG"..., 76}], 2) = 8256
  writev(4, [{"\n@C3A7DACXX140502:3:1209:20684:3"..., 8180}, {"TCATCTGTGAACTCCACCAAGTTTTGTGCCTC"..., 76}], 2) = 8256
  writev(3, [{"\n+\nBA@CCDDDFDFBBDDEBECEDBCCCEBDC"..., 8147}, {"BA?AEEEEECFDBDBBCCECCC?DBBDBDBEA"..., 76}], 2) = 8223
  writev(4, [{"\n+\n&gt;?=@BCE@EDDEEDBDDBDCEBBBBEBED"..., 8147}, {"&gt;?&lt;ABCBBBEDECBCCDBDCDDECBBEBDDDD"..., 76}], 2) = 8223
  </code></pre>
  
  <p>What did I do wrong?</p>