Struct ScratchBuffer

Reusable runtime-capacity contiguous typed buffer.

struct ScratchBuffer(T);

ScratchBuffer owns one backing allocation and exposes an exact live contiguous prefix. Reset ends the live element lifetimes while retaining the established backing capacity for later reuse.

The first public family is thread-confined. It does not provide synchronization, pooling, heterogeneous arena allocation, automatic shrink, or live-element reallocation.

Constructors

NameDescription
this (capacity) Establishes one backing allocation for capacity elements.
this (rhs) Unique owning storage is never copied implicitly.
this (rhs) Transfers the backing allocation without relocating live T values.

Methods

NameDescription
capacity () Backing element capacity retained across reset cycles.
empty () Whether no live elements are stored.
full () Whether the established backing capacity is fully occupied.
length () Number of currently live elements.
opAssign (rhs) Identity assignment is deliberately unavailable.
opIndex (index) Mutable indexed access to one live element.
opSlice () Borrows the exact live contiguous prefix.
reset () Ends all live element lifetimes while retaining backing capacity.
tryPushBack (value) Appends one live element when spare established capacity exists.
tryReserve (minCapacity) Ensures at least minCapacity backing slots without relocating live T.

Example

auto scratch = ScratchBuffer!int(4);

assert(scratch.tryPushBack(10));
assert(scratch.tryPushBack(20));
assert(scratch[] == [10, 20]);

scratch.reset();

assert(scratch.empty);
assert(scratch.capacity == 4);