Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

Dynamic Memory Interface Replacement

renorm
Beginner
269 Views
I need to clarify for myself how exactly TBB Dynamic Memory Interface Replacement (tutorial 10.2.2) works.

As I understand it replaces stock memory manager with the TBB's scalable memory manager, which doesn't guarantee allocation on cash lines. I need to use cache_aligned_allocator explicitly, if false sharing becomes an issue. Right?

Thank you,
renorm.
0 Kudos
2 Replies
Vladimir_P_1234567890
269 Views
Right,
Allocator replacement is for better scalability comparing to stock runtime allocator. But you can use_aligned_mallocfunction on windows for better cache hits. It is replaced also for better scalability.
--Vladimir
0 Kudos
renorm
Beginner
269 Views
Is there any cache aligned version of new, because _aligned_malloc isn't portable and not exactly what I need. Currently I am using my own function to emulate cache aligned new:
[cpp]template 
T* cache_aligned_new(const T& t = T()) {
tbb::cache_aligned_allocator a;
T* p = a.allocate(1);
try {
a.construct(p, t);
} catch (...) {
a.deallocate(p, 1);
throw;
}
return p;
}[/cpp]
Can anyone take a look and check if it is OK?

Another relevant question. Only frequently used variables need to be cache aligned, right?. For example, if x is cache aligned and used frequently, but y isn't cache aligned and used infrequently, it is not a problem if x and y have false sharing. No?

Thank you,
renorm.
0 Kudos
Reply