C++ Standard Library C++ STL Library

C++ unordered_multimap - get_allocator() Function



The C++ unordered_multimap::get_allocator function returns a copy of allocator object associated with the given unordered_multimap.

Syntax

allocator_type get_allocator() const noexcept;

Parameters

None.

Return Value

Returns an allocator associated with the given unordered_multimap.

Time Complexity

Constant i.e, Θ(1).

Example:

In the example below, the unordered_multimap::get_allocator function returns a copy of same allocator object used by the unordered_multimap uMMap.

#include <iostream>
#include <unordered_map>
using namespace std;
 
int main (){
  unordered_multimap<int, string> uMMap;
  pair<const int, string> *p;

  //allocate array with a memory to store 5 
  //elements using unordered_multimap's allocator
  p = uMMap.get_allocator().allocate(5);

  //assign some value to the array
  int psize = sizeof(unordered_multimap<int, string>::value_type)*5;

  cout<<"Allocated size of the array: "<<psize<<" bytes.";

  //destroy and deallocate the array
  uMMap.get_allocator().deallocate(p,5);

  return 0;
}

The output of the above code will be:

Allocated size of the array: 200 bytes.

❮ C++ <unordered_map> Library

5