> 
> **Possible Duplicate:**  
> 
> [How to downsize std::vector?](https://stackoverflow.com/questions/253157/how-to-downsize-stdvector) 
> 
> 
> 

According to cppreference, in std::vector::reserve(size\_t n), n is "Minimum amount desired as capacity of allocated storage.". My question is : how to avoid any reallocation knowing only a maximum ?

As an example, let's say that I have a list of integers, but I don't know the size of this list (for example this list come from the reading of a file). But I know that the maximum size of this list is 1000. Let's say that the real size of the list is 800.

Currently, I use a std::reserve(1000), and then a loop of push\_back(). Using reserve I prevent any reallocation. But how to free the extra space at the end of the push\_backs ? (in the case of the example, how to release the 1000-800=200 extra space ?)

Thank you very much.