Skip to content

Allocator

Spice
import "std/os/allocator";

StorageReport struct

Summary of the allocator's free storage at a glance

StorageReportFull struct

Detailed report of the allocator's free storage, broken down per leaf bin

Allocator struct

An offset allocator that hands out regions from a fixed-size storage area using binned free lists. It manages offsets into an external storage block rather than memory itself, which makes it useful for sub-allocating GPU buffers or other contiguous resources.

Constructors

ctor

Spice
public p Allocator.ctor(UInt32 size, UInt32 maxAllocas = 128 * 1024)

Construct an allocator managing a storage area of the given size

Parameters

Name Type Description
size UInt32 Total size of the managed storage area
maxAllocas UInt32 Maximum number of concurrent allocations to support (default: 128 * 1024)

dtor

Spice
public p Allocator.dtor()

Destruct the allocator, releasing its internal bookkeeping storage

Methods

allocate

Spice
public f<Allocation> Allocator.allocate(UInt32 size)

Allocate a region of the given size from the storage area

Parameters

Name Type Description
size UInt32 Size of the region to allocate

Returns: Allocation — Allocation describing the reserved region

free

Spice
public p Allocator.free(Allocation allocation)

Return a previously allocated region to the allocator

Parameters

Name Type Description
allocation Allocation Allocation to free

Functions

getStorageReport

Spice
public const f<StorageReport> getStorageReport()

Produce a summary report of the allocator's free storage

Returns: StorageReport — Storage report with total free space and largest free region

getStorageReportFull

Spice
public const f<StorageReportFull> getStorageReportFull()

Produce a detailed report of the allocator's free storage, broken down per leaf bin

Returns: StorageReportFull — Full storage report