Using tbb memory allocator

Using tbb memory allocator

I find that I can usee tbb memory allocator for my stl containers in 2 ways

  1. use malloc_proxy
  2. pass scallable_allocator with constructor

Does both give the same result? What I meant is instead of having to replace all my stl constructor's can I achieve the same with malloc_proxy? I need a per thread cache for my object memory allocations.

5 帖子 / 0 全新
最新文章
如需更全面地了解编译器优化,请参阅优化注意事项
Vladimir Polin (Intel)的头像

Quote:

Jithin E. wrote:

Does both give the same result? What I meant is instead of having to replace all my stl constructor's can I achieve the same with malloc_proxy? I need a per thread cache for my object memory allocations.

Hello Jithin,

I general case it is enough. "general case" means that you do not use some custom allocator that calls system functions like VirtualAlloc() or mmap() directly.

--Vladimir

Thanks for clarifying. I tried both approaches and I found performance to be almost similar with malloc_proxy slightly better with multiple threads

But neither solves my broader problem of performance bottle neck with a multi threaded program where each thread create larges amount of objects. I am suspecting that per thread cache overflows for each thread and hence there is a contention at malloc level for each threads.

EDIT: Also how do I give te syntax for a vector of vectors. Eg: - std::vector <std::vector <const char *, tbb::scalable_allocator<const char *> > > x_; For the outer vector I am not able to give an allocator. like std::vector <std::vector <const char *, tbb::scalable_allocator<const char *> >, std::vector > x_;  Gives an error on vector not being a type.

Quote:

Vladimir Polin (Intel) wrote:

Quote:

Jithin E.wrote:

Does both give the same result? What I meant is instead of having to replace all my stl constructor's can I achieve the same with malloc_proxy? I need a per thread cache for my object memory allocations.

Hello Jithin,

I general case it is enough. "general case" means that you do not use some custom allocator that calls system functions like VirtualAlloc() or mmap() directly.

--Vladimir

jimdempseyatthecove的头像

Can you approximate the number of entries for the outer vector?
Generally it would be counter-productive to make the outer vector use a scalable allocator, you would be growing this to a size once. The internal vectors would make sense since these could get recycled (assuming the interior vectors are relatively small).

Jim Dempsey

www.quickthreadprogramming.com

Quote:

jimdempseyatthecove wrote:

Can you approximate the number of entries for the outer vector?
Generally it would be counter-productive to make the outer vector use a scalable allocator, you would be growing this to a size once. The internal vectors would make sense since these could get recycled (assuming the interior vectors are relatively small).

Jim Dempsey

Internal vectors are not that small. Also in places where I am using scalable allocator for vectors the vector size is actually big (about 10000 object pointers) per thread.

登陆并发表评论。