Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
map get_allocator in C++ STL
In this article we will be discussing the working, syntax and examples of map::get_allocator() function in C++ STL.
What is Map in C++ STL?
Maps are the associative container, which facilitates to store the elements formed by a combination on key value and mapped value in a specific order. In a map container the data is internally always sorted with the help of its associated keys. The values in map container is accessed by its unique keys.
What is map::get_allocator()?
The map::get_allocator( ) is a function which comes under <map> header file. get_alloctaor() is used to get the allocator object which is associated with the map container. This function returns the copy of the allocator object of the given map.
Syntax
map_name.get_allocator(key_value k);
Parameters
This function accepts no parameter
Return value
It returns an allocator object of the map.
Example
#include <bits/stdc++.h>
using namespace std;
int main() {
map<int, int> TP;
map<int, int>::allocator_type tp = TP.get_allocator();
cout << "checking Is allocator Pair<int, int> : "<<
boolalpha << (tp == allocator<pair<int, int> >());
return 0;
}
Output
checking Is allocator Pair<int, int> : true
Example
#include <bits/stdc++.h>
using namespace std;
int main(void) {
map<char, int> TP;
pair<const char, int>* TP_pair;
TP_pair = TP.get_allocator().allocate(5);
cout<<"Size after allocating is: " << sizeof(*TP_pair) * 5 << endl;
return 0;
}
Output
Size after allocating is: 40
Advertisements