C++ Standard Library C++ STL Library

C++ multimap - get_allocator() Function



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

Syntax

allocator_type get_allocator() const;
allocator_type get_allocator() const noexcept;

Parameters

None.

Return Value

Returns an allocator associated with the given multimap.

Time Complexity

Constant i.e, Θ(1).

Example:

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

#include <iostream>
#include <map>
using namespace std;
 
int main (){
  multimap<int, string> MMap;
  pair<const int, string> *p;

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

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

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

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

  return 0;
}

The output of the above code will be:

Allocated size of the array: 200 bytes.

❮ C++ <map> Library