In C++, is there a clever (i.e. fast) way to pre-allocate memory for a vector of strings so that each element has some minimum size? The naive way I have is as follows:
vector<string> my_string_vector;
my_string_vector.resize(1000);
for (unsigned int ui=0; ui<1000; ui++)
my_string_vector[ui].reserve(1024);
Many thanks in advance,
Adam
There’s no fast way to do it. You can get fewer lines of code, but you’re still going to make one call to
reservefor eachstd::stringin thestd::vector.I believe EASTL or Boost.Pool may help, if you’re willing to go that route.