ScopedAllocator

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.

Destructor

~this
~this()

ScopedAllocator's destructor releases all memory allocated during its lifetime.

Postblit

this(this)
this(this)

ScopedAllocator is not copyable.

Members

Aliases

Allocator
alias Allocator = AffixAllocator!(ParentAllocator, Node)
Undocumented in source.
parent
alias parent = Allocator.instance
Undocumented in source.

Functions

allocate
void[] allocate(size_t n)

Allocates memory. For management it actually allocates extra memory from the parent.

deallocate
bool deallocate(void[] b)

Deallocates b.

deallocateAll
bool deallocateAll()

Deallocates all memory allocated.

empty
Ternary empty()

Returns Ternary.yes if this allocator is not responsible for any memory, Ternary.no otherwise. (Never returns Ternary.unknown.)

expand
bool expand(void[] b, size_t delta)

Forwards to parent.expand(b, delta).

goodAllocSize
size_t goodAllocSize(size_t n)

Forwards to parent.goodAllocSize (which accounts for the management overhead).

owns
Ternary owns(void[] b)

Forwards to parent.owns(b).

reallocate
bool reallocate(void[] b, size_t s)

Reallocates b to new size s.

Manifest constants

alignment
enum alignment;

Alignment offered

Variables

parent
Allocator parent;

If ParentAllocator is stateful, parent is a property giving access to an AffixAllocator!ParentAllocator. Otherwise, parent is an alias for AffixAllocator!ParentAllocator.instance.

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);

Meta