class StaticAlloc

template<int BlockSize = 512, class DynamicAllocator = TFrameAllocator<BlockSize>>

Static allocator that attempts to perform zero heap (dynamic) allocations by always keeping an active preallocated buffer.

The allocator provides a fixed amount of preallocated memory, and if the size of the allocated data goes over that limit the allocator will fall back to dynamic heap allocations using the selected allocator.

Template parameters

BlockSize

Size of the initially allocated static block, and minimum size of any dynamically allocated memory.

DynamicAllocator

Allocator to fall-back to when static buffer is full.

Public

Constructors

StaticAlloc<BlockSize, DynamicAllocator>

StaticAlloc<BlockSize, DynamicAllocator>() = default

Methods

~StaticAlloc<BlockSize, DynamicAllocator>

~StaticAlloc<BlockSize, DynamicAllocator>() = default

Alloc

u8 *Alloc(u32 amount)

Allocates a new piece of memory of the specified size.

amount
Amount of memory to allocate, in bytes.

Free

void Free(void *data, u32 allocSize)

Deallocates a previously allocated piece of memory.

Free

void Free(void *data)

Deallocates a previously allocated piece of memory.

Clear

void Clear()

Frees the internal memory buffers.

All external allocations must be freed before calling this.

Private

Fields

mStaticData

u8[BlockSize] mStaticData

mFreePtr

u32 mFreePtr

mDynamicAlloc

DynamicAllocator mDynamicAlloc

mTotalAllocBytes

u32 mTotalAllocBytes