Table of Contents

Struct DynamicArena

Namespace
Misaki.HighPerformance.LowLevel.Buffer
Assembly
Misaki.HighPerformance.LowLevel.dll

A dynamic memory management structure that automatically grows by creating linked arenas when more space is needed.

public struct DynamicArena : IMemoryAllocator<DynamicArena, DynamicArena.CreationOptions>, IDisposable
Implements
Inherited Members

Constructors

DynamicArena(nuint)

Initializes a new instance of DynamicArena with the specified initial size.

public DynamicArena(nuint initialSize)

Parameters

initialSize nuint

The initial size in bytes for the first arena block.

Methods

Allocate(nuint, nuint, AllocationOption)

Allocates a block of memory with specified size and alignment. Creates a new arena if current one is full.

public void* Allocate(nuint size, nuint alignment, AllocationOption allocationOption)

Parameters

size nuint

Size of the memory block to allocate in bytes.

alignment nuint

Alignment requirement for the memory block.

allocationOption AllocationOption

Returns

void*

Pointer to the allocated memory block.

Remarks

This is thread safe.

Exceptions

ObjectDisposedException

Thrown if the arena has been disposed.

Create(in CreationOptions)

Creates a new instance of the allocator with the specified options.

public static DynamicArena Create(in DynamicArena.CreationOptions options)

Parameters

options DynamicArena.CreationOptions

Returns

DynamicArena

The created allocator instance.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Free(void*)

Frees a previously allocated block of memory.

public readonly void Free(void* ptr)

Parameters

ptr void*

A pointer to the memory block to free.

Remarks

The pointer must have been returned by a previous call to the Allocate(nuint, nuint, AllocationOption) or Reallocate(void*, nuint, nuint, nuint, AllocationOption) method. After calling this method, the pointer is no longer valid and must not be used.

Reallocate(void*, nuint, nuint, nuint, AllocationOption)

Reallocates a block of memory to a new size and alignment.

public void* Reallocate(void* ptr, nuint oldSize, nuint newSize, nuint alignment, AllocationOption allocationOption)

Parameters

ptr void*

A pointer to the memory block to reallocate.

oldSize nuint

The size of the original memory block.

newSize nuint

The size of the new memory block.

alignment nuint

The alignment of the new memory block.

allocationOption AllocationOption

The allocation options.

Returns

void*

A pointer to the reallocated memory block. null if reallocation fails.

Remarks

The returned pointer must be freed using the Free(void*) method to avoid memory leaks. If the reallocation fails, the original pointer remains valid and must be freed by the caller.

Reset()

Resets all arenas in the chain.

public void Reset()