title: Binary File Read Performance C++
body: <p>I'm trying to read large binary LAS file like this</p>
  
  <pre><code>struct format
  {
      double X;
      double Y;
      double Z;
      short red;
      short green;
      short blue;
      short alpha;
      unsigned long intensity
      // etc.
  }
  
  std::ifstream stream;
  Point3 GetPoint()
  {
      format f;
      stream.seekg(offset);
      offset += sizeof(format);
      stream.Read((char *)f, sizeof(format));
      return Point3(f.X, f.Y, f.Z);
  }
  </code></pre>
  
  <p>In main function:</p>
  
  <pre><code>Point3* points = new Point3[count]
  for (int i = 0; i &lt; count; i++)
      points[i] = GetPoint();
  </code></pre>
  
  <p>This operation takes about 116 seconds with 18million point records. But in a LAS Tool it takes nearly 15 seconds to read and start visualization of the same data.</p>
  
  <p>How it can be fast 7 times then mine's? Is multithreading or something else? If my reading function is not well, how it can be worser 7 times then it?</p>
  
  <p>I have some information about memory mapped files. It is very fast to load whole file to the memory but LAS files can be more then 15GBs which is oversized of my memory size so it will be load to virtual memory. Even I have enough memory I must read the memory mapped file with a loop too.</p>
  
  <p>Can someone give me a help about this situation?</p>