I’m looking for a way that prevents std::vectors/std::strings from growing in a given range of sizes (say I want to assume that a string will hold around 64 characters, but it can grow if needed). What’s the best way to achieve this?
I’m looking for a way that prevents std::vectors/std::strings from growing in a given range
Share
Look at the
.reserve()member function. The standard docs at the SGI site sayThat said, as a general rule unless you really know what is going to happen, it may be best to let the STL container deal with the allocation itself.