title: How to write a large buffer into a binary file in C++, fast?
body: <p>I'm trying to write huge amounts of data onto my SSD(solid state drive). And by huge amounts I mean 80GB.</p>
  
  <p>I browsed the web for solutions, but the best I came up with was this:</p>
  
  <pre><code>#include &lt;fstream&gt;
  const unsigned long long size = 64ULL*1024ULL*1024ULL;
  unsigned long long a[size];
  int main()
  {
      std::fstream myfile;
      myfile = std::fstream("file.binary", std::ios::out | std::ios::binary);
      //Here would be some error handling
      for(int i = 0; i &lt; 32; ++i){
          //Some calculations to fill a[]
          myfile.write((char*)&amp;a,size*sizeof(unsigned long long));
      }
      myfile.close();
  }
  </code></pre>
  
  <p>Compiled with Visual Studio 2010 and full optimizations and run under Windows7 this program maxes out around 20MB/s. What really bothers me is that Windows can copy files from an other SSD to this SSD at somewhere between 150MB/s and 200MB/s. So at least 7 times faster. That's why I think I should be able to go faster.</p>
  
  <p>Any ideas how I can speed up my writing?</p>