title: Access Violation when dealing with large files that cannot be mapped to one view in Win32
body: <p>Good morning, I am trying to write a cMemoryMappedFile class that deals with large files that cannot be mapped to one view in Win32. The code is at the <a href="http://pastebin.com/embed_iframe.php?i=teuGB43x" rel="nofollow">pastebin url</a>.</p>
  
  <p>In GetPointer(), we are trying to carefully map and unmap file regions as they are needed. We are encountering an access violation in GetPointer() on the line marked with the comment // crashes here if adjusted ptr is bad ptr.</p>
  
  <p>The test program is: </p>
  
  <pre><code>int TotalKeys = 2709783;
  try {
      mmapFile = new cMemoryMappedFile(TotalKeys * 54 + 1);   
  }
  catch (cException e) {
      printf("catch cMemoryMappedFile\n");
      throwl     
  }
  
  for (i = 0; i &lt; 50000; i++) {
      mmapFile-&gt;GetPointer(i * 54);
  }
  </code></pre>
  
  <p>When i equals 28521 and i * 54 = 1540134, we get an access violation reading location 0x0024000. The MEM_BLOCK_SIZE is on the 64K alignment required by MapViewOfFile, MEM_BLOCK_SIZE = 65536 * 2. We are running Windows XP Professional Version 2002 Service Pack 3, 32 bit version. What is puzzling is that we are trying the move the map view within the file mapping. Please suggest the cause of the access violation if you wish.</p>
  
  <p>Thank you.</p>