r/cpp • u/Little-Reflection986 • Feb 16 '26
Favorite optimizations ??
I'd love to hear stories about people's best feats of optimization, or something small you are able to use often!
135
Upvotes
View all comments
Show parent comment
2
u/Wargon2015 Feb 19 '26
The trade-off I was referring to was mainly the memory footprint when creating many small vectors with unnecessarily large capacities. Reserving could even be a pessimization if the vector remaining empty is the most common case.
Reserving for a at least a handful of elements (if you're going to inserts at least one) should indeed be considered best practice though.