Note that there are some explanatory texts on larger screens.

plurals
  1. POAccess violation writing newly allocated memory
    primarykey
    data
    text
    <p>I have a program that <strong>intermittently</strong> crashes with "access violation" when running for <strong>long periods of time</strong>. Having debugged it I came across a very strange phenomenon.</p> <p>The program crashes on a code that assigns (copies) one <code>std::vector</code> to another, like this:</p> <pre><code>struct Data { int int1; int int2; } //vec1 is empty //vec2 contains a couple of thousands Data structs std::vector&lt;struct Data&gt; vec1 = vec2;//**crash happens here** </code></pre> <p>What happens is simple - STL allocates a memory block for <code>vec1</code>, and the data from <code>vec2</code> is copied there. Allocation goes fine. Crash happens on the copy process, when STL tries to fill the newly allocated memory for <code>vec1</code> with the data from <code>vec2</code>. What's even more strange, is that some part of that copy process is properly executed, and crash happens somewhere in the middle of that process.</p> <p>My question is - how can a newly allocated memory block be "partly" non-writable? Thank you.</p> <p><strong>EDIT: guys, I don't say that this code has problem - it certainly doesn't. I'm asking why can such type of code crash? I.e. how can the other part of my program modify the memory block that is newly allocated by STL? And how can one debug such memory corruption?</strong></p> <p>And yes, this is the real code</p> <p>Addition: I've enabled <strong>page heap</strong> to see if the problem happened before this code was executed. It didn't catch anything.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload