title: C++ memory mapped files
body: <p>I want to use memory mapping files for data that I read only once. Currently I am using:</p>
  <pre><code>FILE * f = fopen(&quot;data.dat&quot;, &quot;rb&quot;);
  
  fseek(f, 0L, SEEK_END);
  size_t fileSize = ftell(f);
  fseek(f, 0L, SEEK_SET);
  
  char * buffer = new char[fileSize];
  fread(buffer, sizeof(char), fileSize, f);
  fclose(f);
  
  //operate with buffer
  for (size_t i = 0; i &lt; fileSize; i++){ 
    //...
  }
  </code></pre>
  <p>I wanted to use mmap and operate directly on mapped buffer. However, I have found in Apple doc about <code>mmap</code> that there is:</p>
  <blockquote>
  <p>You should not use file mapping in the following situations:</p>
  <ul>
  <li>You want to read a file sequentially from start to finish only once.</li>
  </ul>
  </blockquote>
  <p>Why? If I use <code>fread</code> there is more &quot;logic&quot;, plus I am creating new array, that is also not for free.</p>