c++ - How to completely manage heap memory allocation of std containers like map? -


i'm interested in using multiple std map<int,int> , want of them allocate elements common memory pool. i've read far, can use custom allocators such boost pool_alloc achieve this.

my question is, despite using boost pool_alloc manage allocation of elements themselves, std map still use little bits of heap memory form of container overhead not managed boost pool_alloc? i'm thinking along lines of pointer elements regards use std map itself?

the short version

a map type such as:

typedef std::map<     int,     int,     less<int>,     boost::pool_allocator<pair<const int, int> >     >      amaptype; 

will allocation needs grows using boost::pool_allocators. of initial structure created on stack. how , exact structure though implementation dependent.

allocator rebind

the above possible through use of allocator::rebind

all std::allocator conformant allocators (such boost::pool_allocator) provide rebind template struct in form:

template<class u> struct rebind{    typedef allocatortype<u> other; }; 

this can used obtain same kind of allocator different type:

typedef allocatorofother allocatortype::rebind<adifferenttype>::other; 

gcc std::map internal structure

the g++ std::map implementation (i inspected 4.7.3 , 4.1.1) built purely out of single node type. includes key value pair , pointers , colour bit needed rbtree structure. allocate defines node allocator using rebind struct user provided allocator. used allocations map grows. each new node gets allocated in single allocation.

the standard

i checked though c++11 standard , not find specifying how such structure should allocated. either did not find right part or not specified. not using user given allocator kind seem bit pointless though.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -