Reputation: 161
Is it possible to overload allocator/deallocator of stl::map in c++? If yes then how? Any help would be appreciated.
Upvotes: 2
Views: 1584
Reputation: 372724
Yes, it is possible to do so. If you'll notice, all STL containers are parameterized over a template argument indicating where memory should be obtained from. This is typically done with the STD::allocator type, but you can provide your own custom allocator as well. This is not easy to do because of various design limitations in the allocator requirements, but there are several good links out there. Here's one:
http://www.roguewave.com/Portals/0/products/sourcepro/docs/11.1/html/toolsug/11-6.html
Upvotes: 3
Reputation: 17117
Yes, you can specify it as a template argument:
map<Key, Data, Compare, Alloc>
See http://www.sgi.com/tech/stl/Map.html and http://www.sgi.com/tech/stl/Allocators.html
Upvotes: 4