multimap get_allocator() function in C++ STL

The multimap::get_allocator() is a function in STL in C++ that returns the copy of allocator object associated with this multimap.

Syntax:

multimap.get_allocator()

Return value: This function returns the copy of the allocator object associated with this multimap.



Below example illustrate the get_allocator() method:

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program demonstrate
// multimap::get_allocator()
  
#include <iostream>
#include <map>
using namespace std;
  
int main()
{
    int psize;
    multimap<char, int> mm;
    pair<const char, int>* p;
  
    // allocate an array of 5 elements
    // using mm's allocator:
    p = mm.get_allocator().allocate(5);
  
    // assign some values to array
    psize = sizeof(multimap<char, int>::value_type) * 5;
  
    cout << "The size of allocated array is "
         << psize << " bytes.\n";
  
    mm.get_allocator().deallocate(p, 5);
  
    return 0;
}

chevron_right


Output:

The size of allocated array is 40 bytes.

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to demonstrate
// multimap::get_allocator()
  
#include <iostream>
#include <map>
using namespace std;
  
int main()
{
    int psize;
  
    multimap<char, int> mm;
    pair<const char, int>* p;
  
    // allocate an array of 10 elements
    // using mm's allocator:
  
    p = mm.get_allocator().allocate(10);
  
    // assign some values to array
    psize = sizeof(multimap<char, int>::value_type) * 10;
  
    cout << "The size of allocated array is "
         << psize << " bytes.\n";
  
    mm.get_allocator().deallocate(p, 10);
  
    return 0;
}

chevron_right


Output:

The size of allocated array is 80 bytes.


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.