Do I understand std.experimental.allocator composition correctly?

James Blachly james.blachly at
Mon Aug 26 01:06:55 UTC 2019

The documentation for std.experimental.allocator is a little dense and I 
wanted to make sure I am understanding composition correctly.

Suppose I have the following, taken more-or-less direct from the docs:

     auto batchAllocator = AllocatorList!(
         (size_t n) => Region!Mallocator(max(n, 1024*1024))

Is my understanding correct that Mallocator, the ParentAllocator in 
Region's construction will allocate a block of at least 1 MiB when a 
request comes in, but calls to batchAllocator.make!(T) will allocate 
only enough (rounded up to some ideal like a power of 2) to store T -- 
until it runs out, then the AllocatorList will allocate another block of 
1 MiB, and so on?

Essentially, I need to allocate memory for objects in an inner loop, and 
I thought a better strategy would be to make big block alloc(s) as a 
pool and then hand out internal pointers into the pool. I previously did 
this will malloc() and std.conv.emplace, but this looks like a better 
solution, if my understanding is correct.

Thank you!

More information about the Digitalmars-d-learn mailing list