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
Region is recommended.
import std.experimental.allocator.mallocator : Mallocator; import std.typecons : Ternary; ScopedAllocator!Mallocator alloc; writeln(alloc.empty); // Ternary.yes const b = alloc.allocate(10); writeln(b.length); // 10 writeln(alloc.empty); // Ternary.no
ParentAllocator is stateful,
parent is a property giving access to an
parent is an alias for
parent.goodAllocSize (which accounts for the management overhead).
Allocates memory. For management it actually allocates extra memory from the parent.
b to new size
Deallocates all memory allocated.
Ternary.yes if this allocator is not responsible for any memory,
Ternary.no otherwise. (Never returns
© 1999–2017 The D Language Foundation
Licensed under the Boost License 1.0.