2

Is it possible to overload allocator/deallocator of stl::map in c++? If yes then how? Any help would be appreciated.

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

Comments

3

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.