stdx.allocator.building_blocks.scoped_allocator
-
Declaration
structScopedAllocator(ParentAllocator);delegates all allocation requests to . When destroyed, the object automatically calls for all memory allocated through its lifetime. (The function is also implemented with the same semantics.)
Discussion
is also supported, which is where most implementation effort and overhead of go. If is not needed, a simpler design combining with is recommended.
Examples
import stdx.allocator.mallocator : Mallocator; import stdx.allocator.internal : Ternary; ScopedAllocator!Mallocator alloc; assert(alloc.empty == Ternary.yes); const b = alloc.allocate(10); assert(b.length == 10); assert(alloc.empty == Ternary.no);
-
Declaration
Allocatorparent;If is stateful, is a property giving access to an . Otherwise, is an alias for
AffixAllocator!ParentAllocator.instance. -
Declaration
enum autoalignment;Alignment offered
-
Declaration
size_tgoodAllocSize(size_tn);Forwards to (which accounts for the management overhead).
-
Declaration
void[]allocate(size_tn);Allocates memory. For management it actually allocates extra memory from the parent.
-
Declaration
boolexpand(ref void[]b, size_tdelta);Forwards to .
-
Declaration
boolreallocate(ref void[]b, size_ts);Reallocates to new size .
-
Declaration
Ternaryowns(void[]b);Forwards to .
-
Declaration
booldeallocate(void[]b);Deallocates .
-
Declaration
booldeallocateAll();Deallocates all memory allocated.
-
Declaration
const Ternaryempty();Returns
Ternary.yesif this allocator is not responsible for any memory,Ternary.nootherwise. (Never returnsTernary.unknown.)