std::vector::reserve
From cppreference.com
void reserve( size_type new_cap ); |
||
Increase the capacity of the container to a value that's greater or equal to new_cap
. If new_cap
is greater than the current capacity()
, new storage is allocated, otherwise the method does nothing.
If new_cap
is greater than capacity()
, all iterators and references, including the past-the-end iterator, are invalidated. Otherwise, no iterators or references are invalidated.
Contents |
[edit] Parameters
new_cap | - | new capacity of the container |
[edit] Return value
(none)
[edit] Exceptions
std::length_error if new_cap > max_size().
[edit] Complexity
At most linear in the size()
of the container.
[edit] Note
reserve()
cannot be used to reduce the capacity of the container, to that end shrink_to_fit()
is provided.
[edit] See also
returns the number of elements that can be held in currently allocated storage (public member function) | |
changes the number of elements stored (public member function) | |
(C++11) |
reduces memory usage by freeing unused memory (public member function) |