title: What would be an ideal buffer size?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/236861/how-do-you-determine-the-ideal-buffer-size-when-using-fileinputstream">How do you determine the ideal buffer size when using FileInputStream?</a>  </p>
  </blockquote>
  
  
  
  <p>When reading raw data from a file (or any input stream) using either the C++'s <code>istream</code> family's <code>read()</code> or C's <code>fread()</code>, a buffer has to be supplied, and a number of how much data to read. Most programs I have seen seem to arbitrarily chose a power of 2 between 512 and 4096.</p>
  
  <ol>
  <li>Is there a reason it has to/should be a power of 2, or this just programer's natural inclination to powers of 2?</li>
  <li>What would be the "ideal" number? By "ideal" I mean that it would be the fastest. I assume it would have to be a multiple of the underlying device's buffer size? Or maybe of the underlying stream object's buffer? How would I determine what the size of those buffers is, anyway? And once I do, would using a multiple of it give any speed increase over just using the exact size?</li>
  </ol>
  
  <p><strong>EDIT</strong><br>
  Most answers seem to be that it can't be determined at compile time. I am fine with finding it at runtime.</p>