A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/deque/deque/shrink_to_fit/ below:

public member function

<deque>

std::deque::shrink_to_fit

Shrink to fit

Requests the container to reduce its memory usage to fit its size.

A deque container may have more memory allocated than needed to hold its current elements: this is because most libraries implement deque as a dynamic array that can keep the allocated space of removed elements or allocate additional capacity in advance to allow for faster insertion operations.

This function requests that the memory usage is adapted to the current size of the container, but the request is non-binding, and the container implementation is free to optimize its memory usage otherwise.

Note that this function does not change the size of the container (for that, see resize instead).



Parameters none

Return value none

Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// deque::shrink_to_fit
#include <iostream>
#include <deque>

int main ()
{
  std::deque<int> mydeque (100);
  std::cout << "1. size of mydeque: " << mydeque.size() << '\n';

  mydeque.resize(10);
  std::cout << "2. size of mydeque: " << mydeque.size() << '\n';

  mydeque.shrink_to_fit();

  return 0;
}

Output:
1. size of mydeque: 100
2. size of mydeque: 10


Complexity At most, linear in the container size.

Iterator validity No changes.

Data races The container is modified.
No contained elements are accessed: concurrently accessing or modifying them is safe.

Exception safetyBasic guarantee: if an exception is thrown, the container is in a valid state.

See also
deque::size
Return size (public member function)
deque::resize
Change size (public member function)
deque::clear
Clear content (public member function)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4