title: Is there a way not to use cache in c++
body: <p>This question might be a bit weird but I wonder if there is a way <strong>NOT</strong> to use cache in c++. </p>
  
  <p>I'm doing some tests, in this test I'm loading <code>2 GB (512*4 MB matrices)</code> to memory, then do some correlations among them and calculate performance. </p>
  
  <p>When I run the code for the <strong>1st run</strong>, the running time is <code>t1+x second</code>, in the <strong>2nd run</strong>, total time is <code>t2+x seconds</code> where <code>t1</code> and <code>t2</code> are loading time of 2 GB matrices and <code>t1 &gt; t2</code>. <code>(approx. t1=20, t2=5 sec)</code>. My assumption is it is because in the 2nd run, cache is used. (I don't know if there can be any other reason that decreases loading time like that.)</p>
  
  <p>My problem with this is since there is no standards in loading times, the results are deceptive in some cases. So I want a standard in IO time. The only thing comes to my mind is not to use cache if there is a way.</p>
  
  <p><strong>Is there a way to standardize my IO time</strong>?</p>
  
  <p>I'm using Windows 7 x64 and working on visual studio 2010, my RAM is 32 GB.</p>
  
  <p><strong>TEST RESULTS: I've compared average loading times of 4MB binary file in 5 options.</strong>
  The options are 1st run with my original code, 2nd run with original code, using <strong>FILE_FLAG_NO_BUFFER</strong>, 1st run using cache and 2nd run as <code>Roy Longbottom</code> suggested. </p>
  
  <pre><code>1st run         : 39.1 ms  
  2nd run         : 10.4 ms
  no_buffer       : 127.8 ms
  cache_1st run   : 27.4 ms
  cache_2nd run   : 19.2 ms
  </code></pre>
  
  <p>My original read code is as follows: </p>
  
  <pre><code>void readNoise(string fpath,Mat&amp; data){
      FILE* fp = fopen(fpath.c_str(),"rb");
      if (!fp)perror("fopen");
  
      float* buffer= new float[size];
      for(int i=0;i&lt;size;++i)   {
          fread(buffer,sizeof(float),size,fp);
          for(int j=0;j&lt;size;++j){
              data.at&lt;float&gt;(i,j)=buffer[j];
          }
      }
      fclose(fp);
      free(buffer);
  }
  </code></pre>
  
  <p>I noticed a mistake in my code which is to do dynamic allocation, when I change dynamic allocation to static allocation, running time of <code>readNoise</code> method becomes same as cache used version of <code>Roy Longbottom</code>. </p>
  
  <p>The difference of two run decreased but the question remains the same: "How to standardize running time of both first and second run"?</p>