##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::vector::reserve

From cppreference.com
< cpp‎ | container‎ | vector

[edit template]

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.

### [edit] Parameters

new_cap | - | new capacity of the container
Type requirements
- `T` must meet the requirements of `MoveInsertable`.

### [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] Notes

reserve() cannot be used to reduce the capacity of the container, to that end shrink_to_fit() is provided.

### [edit] See also

capacity | returns the number of elements that can be held in currently allocated storage (public member function) [edit]
resize | changes the number of elements stored (public member function) [edit]
shrink_to_fit (C++11) | reduces memory usage by freeing unused memory (public member function) [edit]

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/container/vector/reserve&oldid=50821"