Question related vector's memory

i know that whenever we use v.push_back(10);
if the size of the vector is full and we do push_back() operation then it doubles the memory is there any way to avoid excessive memory wastage?
ik this vecotr v(size); //it will prevent it but is there any other way ?
and does codechef has any constrain on using vector as if the size is n then vector will almost double it so wont it exceed the given memory condition?

See reserve

3 Likes

you can use vector_name.shrink_to_fit() to get the exact size everytime.

1 Like