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.

replacement of STL::deque

softarts
Beginner
123 Views

on multithread environment, the STL consume too much resource to maintain its freelist (profile with vtune):

i.e.,every container use pthread_mutex_lock to guard the freelist:

can I use TBB to replace stl:deque,vector? and TBB will help to solve this problem?

stl_alloc.h:

template

class __default_alloc_template

{

static void*

allocate(size_t __n)

....

else

{

_Obj* volatile* __my_free_list = _S_free_list

+ _S_freelist_index(__n);

// Acquire the lock here with a constructor call. This

// ensures that it is released in exit or during stack

// unwinding.

_Lock __lock_instance;

_Obj* __restrict__ __result = *__my_free_list;

if (__builtin_expect(__result == 0, 0))

__ret = _S_refill(_S_round_up(__n));

else

{

*__my_free_list = __result -> _M_free_list_link;

__ret = __result;

}

if (__builtin_expect(__ret == 0, 0))

__throw_bad_alloc();

}

0 Kudos
2 Replies
RafSchietekat
Black Belt
123 Views

TBB's container objects are not drop-in replacements for the apparent equivalents in STL, and can't be because of different assumptions. You should study the specifications to see whether they suit your purpose.

If your STL objects are not used across threads, so their only problem is the performance of allocation, and the problem is not at the level of C++ new/delete (which can also be replaced), maybe you could specify your own allocator, and of course use scalable_{malloc,free} for its implementation? Just a thought, I have not looked at the details.

(Added 2010-03-09) That would of course be scalable_allocator, as Alexey writes below.

Alexey_K_Intel3
Employee
123 Views

TBB also provides scalable_allocator suitable to use with STL containers. See scalable_allocator.h. You will need to link with libtbbmalloc.so on Linux; on Windows, tbbmalloc.lib is linked automatically via #pragma comment(lib).

Reply