multimap get_allocator() function in C++ STL
Last Updated :
26 Oct, 2018
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:
#include <iostream>
#include <map>
using namespace std;
int main()
{
int psize;
multimap< char , int > mm;
pair< const char , int >* p;
p = mm.get_allocator().allocate(5);
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:
#include <iostream>
#include <map>
using namespace std;
int main()
{
int psize;
multimap< char , int > mm;
pair< const char , int >* p;
p = mm.get_allocator().allocate(10);
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.
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...