stdx.allocator.building_blocks.scoped_allocator
-
Declaration
struct
ScopedAllocator
(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
Allocator
parent
;If is stateful, is a property giving access to an . Otherwise, is an alias for
AffixAllocator!ParentAllocator.instance
. -
Declaration
enum auto
alignment
;Alignment offered
-
Declaration
size_t
goodAllocSize
(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
bool
expand
(ref void[]b
, size_tdelta
);Forwards to .
-
Declaration
bool
reallocate
(ref void[]b
, size_ts
);Reallocates to new size .
-
Declaration
Ternary
owns
(void[]b
);Forwards to .
-
Declaration
bool
deallocate
(void[]b
);Deallocates .
-
Declaration
bool
deallocateAll
();Deallocates all memory allocated.
-
Declaration
const Ternary
empty
();Returns
Ternary.yes
if this allocator is not responsible for any memory,Ternary.no
otherwise. (Never returnsTernary.unknown
.)