title: C++ Load binary file in memory and get the objects
body: <p>I have a binary file in which I save the following variables millions of times:</p>
  
  <ul>
  <li>a x-size vector of floats</li>
  <li>two unsigned integers</li>
  </ul>
  
  <p>Currently I'm using ifstream for opening and reading the file but I was wondering if I could speed up the execution time by loading the whole file into memory and reducing the I/Os.</p>
  
  <p>How can I load the file into memory and then convert it into the variables I want? With ifstream this is done easily but I don't know how to buffer it and then extract the data.</p>
  
  <p>This is the code I'm using to save the data:</p>
  
  <pre><code>osfile.write(reinterpret_cast&lt;const char*&gt; (&amp;sz), sizeof(int));// Size of vector
  osfile.write(reinterpret_cast&lt;const char*&gt; (&amp;vec[0]), sz*sizeof(float));
  osfile.write(reinterpret_cast&lt;const char*&gt; (&amp;a), sizeof(unsigned int));
  osfile.write(reinterpret_cast&lt;const char*&gt; (&amp;b), sizeof(unsigned int));
  </code></pre>