Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2008-01-31 21:43:35


on Sun Dec 30 2007, Robin <al-AT-cyberversion.com> wrote:

>> My understanding is that the pool allocator is made for repeated
>> allocation and deallocation of same-sized blocks, in which case the
>> result makes sense. I think it's more intended for use with
>> node-based containers such as list and map.
>
> I tried with list, the std::allocator is still faster
>
> typedef list <A, boost::pool_allocator <list <A>::value_type > > ListA;
> ListA listA;
>
> then
>
> listA.push_back (A ());
> listA.pop_front ();
>
> Or with boost::shared_ptr as I need to keep a polymorphic pointer.
>
> typedef list < boost::shared_ptr <A>, boost::pool_allocator <A> > ListA;
> ListA listA;
>
> then
>
> listA.push_back (boost::shared_ptr <A> (new A ()));
> listA.pop_front ();
>
>
> I can't get map to compile,
>
> typedef map <string, A, boost::pool_allocator <std::map <string,A>::value_type >
>> MapA;
> MapA mapA;
>
> mapA.insert (make_pair ("test",A ()));
>
> VC8 balks at this line at the xutility comparision predicate header. It compiles
> fine with the std allocator.
>
> Am I using pool incorrectly?

Yes. list<A, whateverallocator> doesn't allocate blocks of size
sizeof(list<A>::value_type). Instead, it allocates a (larger) node size
that you can't know without looking at list's implementation details.
If you want to make an efficient pool allocator, you need its allocation
size to be the same as that of the nodes being allocated.

-- 
Dave Abrahams
Boost Consulting
http://boost-consulting.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk