Class AllocationManager
- Namespace
- Misaki.HighPerformance.LowLevel.Buffer
- Assembly
- Misaki.HighPerformance.LowLevel.dll
Provides memory allocation management for native memory allocations, with support for tracking, debugging, and custom allocation strategies.
public static class AllocationManager
- Inheritance
-
AllocationManager
- Inherited Members
Properties
LiveAllocationCount
Gets the number of live tracked heap allocations. Always returns 0 if MHP_ENABLE_SAFETY_CHECKS is disabled.
public static int LiveAllocationCount { get; }
Property Value
TotalAllocatedMemory
public static nuint TotalAllocatedMemory { get; }
Property Value
Methods
AddAllocation(void*, nuint)
Registers a memory allocation and returns a handle that can be used to manage or reference the allocated memory.
public static MemoryHandle AddAllocation(void* ptr, nuint size)
Parameters
ptrvoid*A pointer to the memory block to be registered. The pointer must reference a valid, allocated memory region.
sizenuintThe newSize of the memory block to be registered.
Returns
- MemoryHandle
A MemoryHandle representing the registered allocation.
Remarks
Always returns an invalid handle if MHP_ENABLE_SAFETY_CHECKS is disabled.
ContainsAllocation(MemoryHandle)
Determines whether the specified memory handle refers to a currently tracked allocation.
public static bool ContainsAllocation(MemoryHandle handle)
Parameters
handleMemoryHandleThe memory handle to check for an associated allocation.
Returns
- bool
true if the allocation corresponding to the handle exists; otherwise, false.
Remarks
This only validates the memory when you added the allocation via AddAllocation(void*, nuint). Always returns false if debug layer is disabled.
CreateStackScope()
Creates a new thread local stack scope for managing temporary allocations within the current context.
public static VirtualStack.Scope CreateStackScope()
Returns
- VirtualStack.Scope
A Stack.Scope instance representing the newly created stack scope. The scope must be disposed when no longer needed to release allocated resources.
Dispose()
Disposes of the AllocationManager, freeing all allocated memory and resources.
public static void Dispose()
Initialize(AllocationManagerDesc)
public static void Initialize(AllocationManagerDesc desc = default)
Parameters
RemoveAllocation(MemoryHandle)
Removes the memory allocation associated with the specified handle.
public static bool RemoveAllocation(MemoryHandle handle)
Parameters
handleMemoryHandleThe handle representing the memory allocation to remove. The handle must be valid and previously allocated.
Returns
- bool
true if the allocation was successfully removed; otherwise, false.
Remarks
Always returns false if debug layer is disabled.
ResetTempAllocator()
Resets the temporary memory allocator, clearing all allocated memory.
public static void ResetTempAllocator()
TryGetAllocation(MemoryHandle, out AllocationInfo)
Attempts to retrieve the memory allocation pointer associated with the specified handle.
public static bool TryGetAllocation(MemoryHandle handle, out AllocationInfo info)
Parameters
handleMemoryHandleThe memory handle identifying the allocation to retrieve allocation.
infoAllocationInfoWhen this method returns, contains the allocation information associated with the specified handle, if the allocation was found; otherwise, an uninitialized value.
Returns
- bool
true if the allocation was found and
infocontains valid allocation information; otherwise, false.
Remarks
Always returns false if debug layer is disabled, and the output pointer will be set to Zero.
UpdateAllocation(MemoryHandle, void*, nuint)
public static void UpdateAllocation(MemoryHandle handle, void* newPtr, nuint newSize)
Parameters
handleMemoryHandlenewPtrvoid*newSizenuint