Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.
Announcements
This community is designed for sharing of public information. Please do not share Intel or third-party confidential information here.

Using tbb memory allocator

Jithin_E_
Beginner
130 Views

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.

0 Kudos
4 Replies
Vladimir_P_Intel2
130 Views

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

Jithin_E_
Beginner
130 Views

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.

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
Black Belt
130 Views

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

Jithin_E_
Beginner
130 Views

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.

Reply