Boost logo

Boost :

Subject: Re: [boost] [pool] Thread specific pool allocator
From: OvermindDL1 (overminddl1_at_[hidden])
Date: 2009-09-12 14:55:00

On Sat, Sep 12, 2009 at 10:01 AM, James Bremner <ravenspoint_at_[hidden]> wrote:
> I develop code to run on multiple processor machines. Moderate use of the
> standard template library (STL) containers cause programs to slow down when
> the work is split between threads running on different processors.  This is
> because the STL default memory allocator is a thread-safe singleton and
> causes contention between the threads.
> The memory allocator provided by boost::pool_allocator is also a thread safe
> singleton.
> I have coded a thread specific memory allocator based on boost::pool and
> boost:thread_specific_pointer.  My allocator creates a new instantiation for
> each thread it is used in, and so avoids contention between threads.  The
> containers created with this allocator must be used carefully, not written
> to by more than one thread, because the allocator is not thread-safe ( that
> is the point! ) - however they provide dramatic performance improvements
> when my code runs on multiple processors.
> I do not expect my coding is to the high standard of the boost libraries,
> but I do believe it shows that something very useful can be done with a few
> lines of code.  Any chance of a boost:thread_specific_pool_allocator in the
> near future?

As I recall, Boost already have such a thread-specific allocator for
things that Boost.Pool could use.

If all your objects are the same size, Boost.Pool is great.
If you want to allocate things of many different sizes, then I
recommend tcmalloc from google ( there are other things in
that library too, but the memory allocator by itself is awesome).
tcmalloc is basically like a lot of variable sized boost.pools
allocated within each other and so forth, wonderful speed, I know of
nothing that beats it. It is actually a rather simple design and I
had something similar already made that I used a few years back (built
off of boost.pool, but due to some of boost.pool's design it does not
quite reach the same speed).

Boost list run by bdawes at, gregod at, cpdaniel at, john at