I read many questions on this topic on stackoverflow. However, I couldn't find my answer in any of them. Hence, this question.
I have
vector< vector< int > > temp
I can reserve memory for outer vector :
temp.reserve(20);
Now, I want to reserve memory for each inside vector. I can do this using:
temp[i].reserve(500);
However, if I use temp.clear(); then the capacity of temp is retained as 20. However, now if I initialize the temp vector with 20 inner vectors, the capacity of these inner vectors is reset to 0 (according to VS2010 Intellisense).
My questions:
How can I retain the inner vector capacity of 500 even after I clear and re-initialize the outer vector?
I am using OpenCV findContours function. This function clears the outer vector and fills it with new set of inner vectors. Does this function cause deallocation and re-allocation of memory?
std::vector::clearpreserves the reserved capacity? - jamesdlinclear(although I can't remember which compiler it was). - Mark Bclear()may or may not release the memory. Actually that detail is implementation-specific. It is not mandatory in any C++ standard. - Frunsi