简体   繁体   中英

Overload Allocator and deallocator of stl::map in c++

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM