Struct Arena
- Namespace
- Misaki.HighPerformance.LowLevel.Buffer
- Assembly
- Misaki.HighPerformance.LowLevel.dll
A memory management structure that allocates and resets memory blocks with specified alignment.
public struct Arena : IMemoryAllocator<Arena, Arena.CreationOptions>, IDisposable
- Implements
- Inherited Members
Constructors
Arena(nuint)
public Arena(nuint size)
Parameters
sizenuint
Properties
Buffer
public readonly byte* Buffer { get; }
Property Value
- byte*
Offset
public readonly nuint Offset { get; }
Property Value
Size
public readonly nuint Size { get; }
Property Value
Methods
Allocate(nuint, nuint, AllocationOption)
Allocates a block of memory of a specified size with a given alignment.
public void* Allocate(nuint size, nuint alignment, AllocationOption allocationOption)
Parameters
sizenuintSpecifies the amount of memory to allocate in bytes.
alignmentnuintDefines the alignment requirement for the allocated memory.
allocationOptionAllocationOptionThe option when allocating memory.
Returns
- void*
A pointer to the allocated memory block or null if the allocation cannot be fulfilled.
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 Arena Create(in Arena.CreationOptions opts)
Parameters
optsArena.CreationOptionsThe options for creating the allocator.
Returns
- Arena
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
ptrvoid*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
ptrvoid*A pointer to the memory block to reallocate.
oldSizenuintThe size of the original memory block.
newSizenuintThe size of the new memory block.
alignmentnuintThe alignment of the new memory block.
allocationOptionAllocationOptionThe 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 the arena.
public void Reset()