0
Shrink to fit reallocation
Hi Please refer code below: I know shrink to fit is implementation specific and may or may not re allocate the data again? Question is about the way to avoid the reallocation. Can move help or re allocation is non avoidable in any means ? https://sololearn.com/compiler-playground/cJT2gcb8CMAj/?ref=app
2 Answers
+ 1
from google:
"The usual way to avoid vector reallocation is to to use the reserve() function to reserve, up front, enough memory for a given number of elements."
so...
create a large enough vector capacity.
try not to exceed it.
avoid using shrink_to_fit.
+ 1
That's true . Just curious whether is it possible to avoid re allocation if shrink to fit was used.