Memory Allocation

Intel® Threading Building Blocks (Intel® TBB) provides several memory allocator templates that are similar to the STL template class std::allocator. Two templates, scalable_allocator<T> and cache_aligned_allocator<T>, address critical issues in parallel programming as follows:

You can use these allocator templates as the allocator argument to STL template classes. The following code shows how to declare an STL vector that uses cache_aligned_allocator for allocation:

std::vector<int,cache_aligned_allocator<int> >;

Tip

The functionality of cache_aligned_allocator<T> comes at some cost in space, because it must allocate at least one cache line’s worth of memory, even for a small object. So use cache_aligned_allocator<T> only if false sharing is likely to be a real problem.

The scalable memory allocator also provides a set of functions equivalent to the C standard library memory management routines but has the scalable_ prefix in their names, as well as the way to easily redirect the standard routines to these functions.