title: Buffer Size in C++
body: <p>I am observing the following behavior with the C++ Std library method std::ostream::write().</p>
  
  <p>For buffering the data I am making use of the following C++ API</p>
  
  <pre><code>std::ofstream::rdbuf()-&gt;pubsetbuf(char* s, streamsize n)
  </code></pre>
  
  <p>This works fine ( verified using the strace utility ) as long as the size of data (datasize)  we are writing on the file stream using</p>
  
  <pre><code>std::ofstream::write (const char* s, datasize n)
  </code></pre>
  
  <p>Is less than 1023 bytes ( below this value the writes are accumulated till the buffer is not full), but when the size of data to write exceeds 1023, the buffer is not taken into account and the data is flushed to the file.</p>
  
  <p>e.g. If I set the buffer size to 10KB and write around 512bytes a time, strace will show that multiple writes have been combined into a single write</p>
  
  <pre><code>writev(3, [{"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"..., 9728}, {"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"..., 512}], 2) = 10240 ( 10 KB )
  writev(3, [{"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"..., 9728}, {"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"..., 512}], 2) = 10240
  ...
  </code></pre>
  
  <p>but when I write 1024 bytes a time ( keeping the buffer fixed to 10 KB), now strace shows me that it is not using the buffer and each ofstream::write call is being translated to write system call.</p>
  
  <pre><code>writev(3, [{NULL, 0}, {"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"..., 1024}], 2) = 1024 ( 1KB )
  writev(3, [{NULL, 0}, {"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"..., 1024}], 2) = 1024
  ...
  </code></pre>
  
  <p>Is there any C++ API Call or Linux Tuning Parameter which I am missing?</p>