Using the string :: reserve

When is it advisable to use string::reserve? I understand that it is used to reserve a certain number of characters for a string to hold, but how can this be useful? Is the string still changing if you go over? Does efficiency increase?

+1
source share
1 answer

It will "reserve" the specified space to reduce the number of redistributions. If you have a good idea about how big the row will be, then reserving that amount of space should prevent any redistribution.

If you upgrade, it will resize, but the idea is to reduce the number of redistributions.

+4
source

All Articles