std.experimental.allocator.building_blocks.scoped_allocator
struct ScopedAllocator
Types 1
structScopedAllocator(ParentAllocator)
ScopedAllocator delegates all allocation requests to ParentAllocator. When destroyed, the ScopedAllocator object automatically calls deallocate for all memory allocated through its lifetime. (The deallocateAll function is also implemented with the same semantics.)
deallocate is also supported, which is where most implementation effort and overhead of ScopedAllocator go. If deallocate is not needed, a simpler design combining AllocatorList with Region is recommended.
Fields
private Node * rootAllocator.alignment alignmentAlignment offeredprivate q{
if (!b.ptr) return b;
Node* toInsert = & parent.prefix(b);
toInsert.prev = null;
toInsert.next = root;
toInsert.length = n;
assert(!root || !root.prev);
if (root) root.prev = toInsert;
root = toInsert;
return b;
} _processAndReturnAllocateResultMethods
size_t goodAllocSize(size_t n)Forwards to `parent.goodAllocSize` (which accounts for the management overhead).void[] allocate(size_t n)Allocates memory. For management it actually allocates extra memory from the parent.bool reallocate(ref void[] b, size_t s)Reallocates `b` to new size `s`.bool deallocateAll()Deallocates all memory allocated.Destructors
~this`ScopedAllocator`'s destructor releases all memory allocated during its lifetime.Nested Templates
Node