views:

1255

answers:

4

I've played with boost::pool a few times in places where it seemed to me I was seriously hammering the heap with a lot of object "churn". Generally I've used boost::object_pool, or boost::pool_alloc as an STL template parameter. However the result is invariably that performance is virtually unchanged, or significantly worsened.

I'm curious to hear of any success stories with it.

What sort of things should I look for in profiling output which might indicate boost::pool is likely to help ?

Is it just actually pretty hard to improve on good old malloc ?

+2  A: 

You might want to track down your performance problems to memory allocations first before you start to optimize for that.

So, narrow down your profiling to pinpoint the location of the problem. This can be lots of calls to the same code that might not take long when only called once.

HS
+4  A: 

Blind optimizations are not good. Try to use google memory allocator, you don't even need to recompile your application. You can find what you need to know in here:

http://google-perftools.googlecode.com/svn/trunk/doc/tcmalloc.html

Gaetano

Gaetano Mendola
Thanks for the pointer. One of the things I was playing with was thread-specific memory pools, but tcmalloc looks like a cleaner way of getting them.
timday
+6  A: 

Memory pools are most effective imo for transaction style processing where you can allocate to the pool and then when the transaction is done, just dump it into oblivion. The real speed up isn't that each allocation is going to be much faster its that you will have near zero memory fragmentation in an extremely long running application.

In sort, it sounds like your applications do not warrant using memory pools

Hippiehunter
Well this one actually answered the question (although I'm certainly guilty of premature optimisation in this case, as noted by the other replies).
timday
+1  A: 

Yes, 500% speed increase. The application (rather stupidly, but sometimes you have to work with what you got) copied elements from 1 std::map to another in a loop (there was some decision making in the loop), and the resulting allocations on multithreaded/process servers resulted in heap contention. I added the boost pool as an allocator on the second map and the result was a 500% increase in application execution speed.

Ian