Hi, I have a question about the std::vector.
I have a very memory intensive algorithm where I forsee that predicting vector sizes and reserving enough memory for the vectors in advance will help me a lot with reducing memory usage.
Which of the following is better:
for ( ... ) {
std::vector<Type> my_vector;
my_vector.reserve(stuff_count);
// Do stuff , and append stuff to my_vector.
}
Or this:
std::vector my_vector;
for ( ... ) {
my_vector.clear();
my_vector.reserve(stuff_count);
// Do stuff , and append stuff to my_vector.
}
Please tell me which is best, or if there is an even better way of doing stuff.
Thank you very much in advance!