Allocators stack

Allocator stack via Digitalmars-d digitalmars-d at puremagic.com
Mon Dec 22 08:51:28 PST 2014


How about allocators stack? Allocator e.g. one of these
https://github.com/andralex/phobos/blob/allocator/std/allocator.d
-------------
allocatorStack.push(new GCAllocator);
//Some code that use memory allocation
auto a = ['x', 'y'];
a ~= ['a', 'b']; // use allocatorStack.top.realloc(...);
allocatorStack.pop();
-------------
Allocators must be equipped with dynamic polymorphism. For those
cases when it is too expensive attribute
@allocator(yourAllocator) applied to declaration set allocator
statically.

-------------
@allocator(Mallocator.instance)
void f()
{
// Implicitly use global(tls?) allocator Mallocator when allocate 
an
object or resize an array or etc.
}

@allocator("StackAllocator")
void f()
{
// Implicitly use allocatorStack.top() allocator when allocate an
object or resize an array or etc.
}
-------------

There is some issues to solve. E.g. how to eliminate mix memory 
from different allocators.


More information about the Digitalmars-d mailing list