Skip to content

Offset Allocator

Spice
import "std/os/offset-allocator";

Allocation struct

Fields

Name Type Description
offset unsigned int

Region struct

One size class of the allocator's free storage, used by getStorageReportFull()

Fields

Name Type Description
size unsigned int
count unsigned int

StorageReport struct

Summary of the allocator's free storage at a glance

Fields

Name Type Description
totalFreeSpace unsigned int
largestFreeRegion unsigned int

StorageReportFull struct

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

Fields

Name Type Description
freeRegions Region[NUM_LEAF_BINS]

Constructors

ctor

Spice
public p StorageReportFull.ctor()

Default-construct an empty full storage report; every entry is filled in by getStorageReportFull()

OffsetAllocator 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.

The allocator owns its bookkeeping storage (the node pool and free list), so it must not be shallow-copied; copying (via the copy ctor or operator=) allocates and deep-copies fresh bookkeeping storage.

Constructors

ctor

Spice
public p OffsetAllocator.ctor(unsigned int size, unsigned int maxAllocas = 128 * 1024)

Construct an allocator managing a storage area of the given size

Parameters

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

ctor

Spice
public p OffsetAllocator.ctor(const OffsetAllocator& original)

Construct an allocator as a deep copy of another allocator, so the two do not share bookkeeping storage

Parameters

Name Type Description
original const OffsetAllocator& OffsetAllocator to copy

dtor

Spice
public p OffsetAllocator.dtor()

Destruct the allocator, releasing its internal bookkeeping storage

Methods

allocate

Spice
public f<Allocation> OffsetAllocator.allocate(unsigned int size)

Allocate a region of the given size from the storage area

Parameters

Name Type Description
size unsigned int Size of the region to allocate

Returns: Allocation — Allocation describing the reserved region

free

Spice
public p OffsetAllocator.free(Allocation allocation)

Return a previously allocated region to the allocator

Parameters

Name Type Description
allocation Allocation Allocation to free

getStorageReport

Spice
public const f<StorageReport> OffsetAllocator.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> OffsetAllocator.getStorageReportFull()

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

Returns: StorageReportFull — Full storage report

Operators

operator=

Spice
public p operator=(OffsetAllocator& this, const OffsetAllocator& newValue)

Copy-assign the bookkeeping storage of another allocator into this one

Parameters

Name Type Description
newValue const OffsetAllocator& OffsetAllocator to copy from