Table of Contents

Struct VirtualStack

Namespace
Misaki.HighPerformance.LowLevel.Buffer
Assembly
Misaki.HighPerformance.LowLevel.dll
public struct VirtualStack : IMemoryAllocator<VirtualStack, VirtualStack.CreationOptions>, IDisposable
Implements
Inherited Members

Constructors

VirtualStack(nuint)

public VirtualStack(nuint reserveCapacity)

Parameters

reserveCapacity nuint

Properties

Allocated

public readonly nuint Allocated { get; }

Property Value

nuint

Buffer

public readonly byte* Buffer { get; }

Property Value

byte*

Committed

public readonly nuint Committed { get; }

Property Value

nuint

Reserved

public readonly nuint Reserved { get; }

Property Value

nuint

Methods

Allocate(nuint, nuint, AllocationOption)

Allocates a block of memory of the specified size and alignment.

public void* Allocate(nuint size, nuint alignment, AllocationOption option = AllocationOption.None)

Parameters

size nuint
alignment nuint
option AllocationOption

Returns

void*

Remarks

This is not thread-safe. It is designed for single-threaded or thread-local contexts.

Create(in CreationOptions)

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

public static VirtualStack Create(in VirtualStack.CreationOptions opts)

Parameters

opts VirtualStack.CreationOptions

The options for creating the allocator.

Returns

VirtualStack

The created allocator instance.

CreateScope(AllocationHandle)

Creates a new scope instance associated with the current stack context.

public VirtualStack.Scope CreateScope(AllocationHandle handle)

Parameters

handle AllocationHandle

Returns

VirtualStack.Scope

A VirtualStack.Scope object that represents a scope tied to this stack.

Remarks

The instance of VirtualStack must be pinned or allocated on the native heap to ensure that the pointer remains valid for the lifetime of the scope.

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 the internal offset to its initial position, keeping the committed physical memory intact for future reuse.

public void Reset()