Take the 2-minute tour ×

I need some fast, thread safe memory pooling library. I've googled a lot, but fast solutions don't have thread safety, while others are really big.

Any suggestions?

share|improve this question
Why not just malloc()? It is too slow? Did you try some per-thread pool? It is faster, but waste some memory. –  J-16 SDiZ Jan 25 '11 at 4:15
i have hundrends of malloc/free per second with small chunks (<500b), so yes, just free/malloc are really slow. i also would like to get some thread safe solution so i won't have headache about pool management in threads. –  Daniel Jan 25 '11 at 4:36
Also consider arena memory management. If it is suitable for you it will be many times faster. –  Joshua Jan 25 '11 at 18:37
add comment

4 Answers

up vote 4 down vote accepted

Both nedmalloc and ptmalloc are C based thread caching memory managers, based around doug lea's malloc(the core of most linux allocators). They are both under good licences as well, unlike hoard, which requires payment for commercial use, last I looked. Googles tcmalloc also has C bindings iirc, and is built from the ground up as a thread caching allocator, as well as some built in heap and cpu profiling tools, it is however build for massive memory usage(the example they give is 300mb+ per thread), and as such many not work as well as expected for smaller scale apps

share|improve this answer
thank you! nedmalloc is exactly what i was looking for. –  Daniel Jan 25 '11 at 5:00
add comment

You're supposed to use one memory pool per thread.

share|improve this answer
Note that while this can help, there are still threading issues that need attention - while you can ensure that an allocation from a particular thread can be directed to a particular pool, you have to be prepared to free a block for any pool from any thread. –  Michael Burr Jan 25 '11 at 4:28
why am i supposed to use separate memory pools for each thread? –  Daniel Jan 25 '11 at 4:37
This can also lead to one thread arena reserving hundreds of megs of memory in its free store, starving other thread arena who actually need to allocate the memory –  Necrolis Jan 25 '11 at 4:52
This permits high speed by not requiring a semaphore. In order to do this you need a whole-program optimization to ensure that anybody using the memory pool never deallocates via the wrong pool. –  Joshua Jan 25 '11 at 16:11
This sounds like a great idea, but apparently there is no support for it in the C standard library. Do you know of any good pool allocator libraries for C? I was interested in talloc, but I would like something that does not add the overhead of dynamically calling destructors. –  Eduardo León Feb 19 at 23:19
show 1 more comment

The Apache Portable Runtime works well and shouldn't be all that big.

share|improve this answer
i've tried apr as first approach and it is really big + has too much api i won't use at all. –  Daniel Jan 25 '11 at 4:36
add comment

Have you tried Hoard?

See also these two articles from Intel.com

share|improve this answer
i've seen it, but it seems to be more like a hack that bolts on existing application (LD_PRELOAD), while i need to have some control over pool (size, max size, current usage, etc...) –  Daniel Jan 25 '11 at 4:39
add comment

Your Answer


