title: Fast way to "backup" (copy) large STL vector of custom objects
body: <p>I'm using a STL vector to store a large (~ 10^6) number of custom objects (sizeof() gives 368 bytes for one of these objects). The structure of my program requires me to make frequent backup copies of this vector as changes made in a certain step might need to be unrolled under certain conditions. Roughly this looks something like</p>
  
  <pre><code>std::vector&lt;myClass&gt; vecA( largeNumber );
  std::vector&lt;myClass&gt; vecB;
  
  do
  {
    vecB = vecA;
  
    //do lots of stuff to vecA
  
    if ( restoreBackup ) { vecA = vecB; }
  
  } while (someCondition)
  </code></pre>
  
  <p>Doing some profiling, the copy operation <code>vecB = vecA</code> is actually a considerable bottle neck. I really need to speed up this part. Which strategies would you suggest? </p>
  
  <p>Remarks: </p>
  
  <ul>
  <li>For certain reasons I would like to keep the STL vector structure.</li>
  <li>I know that most of the times only a small fraction of the elements in vecA gets updated. So I could try to maintain an extra list of these elements and then only copy these elements back and forth by looping over this list. Would that be an adequate strategy?</li>
  <li>The question is certainly related to <a href="https://stackoverflow.com/questions/644673/fast-way-to-copy-one-vector-into-another">this question</a>, however the solutions proposed there don't really help.</li>
  </ul>