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
std::vector<myClass> vecA( largeNumber );
std::vector<myClass> vecB;
do
{
vecB = vecA;
//do lots of stuff to vecA
if ( restoreBackup ) { vecA = vecB; }
} while (someCondition)
Doing some profiling, the copy operation vecB = vecA
is actually a considerable bottle neck. I really need to speed up this part. Which strategies would you suggest?
Remarks:
- For certain reasons I would like to keep the STL vector structure.
- 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?
- The question is certainly related to this question, however the solutions proposed there don't really help.