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:
// 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; } |
Output:
The size of allocated array is 40 bytes.
Example 2:
// 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; } |
Output:
The size of allocated array is 80 bytes.
Contact Us