When is it appropriate to use string::reserve?
I realize that it is used to reserve a certain amount of characters for the string to hold but how can this be useful? Does the string still resize if you go over? Does it add a level of efficiency?
When is it appropriate to use string::reserve ? I realize that it is used
Share
It will “reserve” the specified space to reduce the number of reallocations. If you have a good idea of how big the string will get, then reserving that amount of space should prevent any reallocation.
If you go over, it will resize, but the idea is to reduce the number of reallocations.