I have a question about std :: vector.
I have an algorithm with intensive memory in which I predict that predicting the size of vectors and reserving enough memory for vectors will help me in advance with decreasing memory usage.
Which of the following is better:
for ( ... ) {
std::vector<Type> my_vector;
my_vector.reserve(stuff_count);
}
Or that:
std::vector my_vector;
for ( ... ) {
my_vector.clear();
my_vector.reserve(stuff_count);
}
Please tell me which is better, or if there is an even better way to do things.
Thank you in advance!
source
share