I wanted to try out TBB\'s scalable_allocator, but was confused when I had to replace some of my code. This is how allocation is done with the allocator:
Som
The parameter to allocate()
is the number of objects, not the size in bytes.
You then call the allocator's construct()
function to construct the object.
scalable_allocator sa;
SomeClass* s = sa.allocate(1);
sa.construct(s, SomeClass());
// ...
sa.destroy(s);
sa.deallocate(s);
If want to use it with a standard library container or other std allocator aware type, simply give it the allocator type.
std::vector> v;