title: Read access violation for memory mapped vector in debug mode
body: <p>While attempting to use <code>boost::interprocess</code> for storing a <code>std::vector</code> in a memory mapped file, I am getting the exception <code>Exception thrown: read access violation.</code> when I try to push back on a loaded vector, but <strong>only in debug mode</strong>.</p>
  
  <p>This minimal example code (written by @sehe) is retrieved from <a href="https://stackoverflow.com/a/29602884/2741329">https://stackoverflow.com/a/29602884/2741329</a>, and it crashes on MSVC14 in debug mode <strong>and</strong> executed more than once:</p>
  
  <pre><code>#include &lt;boost/interprocess/managed_mapped_file.hpp&gt;
  
  namespace bi = boost::interprocess;
  
  int main() {
      std::string vecFile = "vector.dat";
      bi::managed_mapped_file file_vec(bi::open_or_create,vecFile.c_str(), 1000);
  
      typedef bi::allocator&lt;int, bi::managed_mapped_file::segment_manager&gt; int_alloc;
      typedef std::vector&lt;int, int_alloc&gt;  MyVec;
  
      MyVec * vecptr = file_vec.find_or_construct&lt;MyVec&gt;("myvector")(file_vec.get_segment_manager());
  
      vecptr-&gt;push_back(rand());
  }
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>This is the Visual Studio error message:</p>
  
  <p><a href="https://i.stack.imgur.com/Ui3Nj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ui3Nj.png" alt="enter image description here"></a></p>
  
  <p>Here the point where the exception happens:</p>
  
  <p><a href="https://i.stack.imgur.com/QtlNr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QtlNr.png" alt="enter image description here"></a></p>
  
  <p>This is the call stack (click on the pic to enlarge it):</p>
  
  <p><a href="https://i.stack.imgur.com/TwJQj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TwJQj.png" alt="enter image description here"></a></p>