feat(memory): add generic IMemoryAllocator and MemoryPool

Refactored Arena, DynamicArena, FreeList, and Stack to implement the new IMemoryAllocator<TSelf, TOpts> interface, standardizing allocation and free methods. Introduced MemoryPool<T, TOpts> for allocator lifetime management and AllocationHandle access. Updated Program.cs to use MemoryPool, replacing AllocationManager. Minor project file updates included.
This commit is contained in:
2026-03-18 21:19:51 +09:00
parent 641b459997
commit faf87953a3
8 changed files with 150 additions and 21 deletions

View File

@@ -6,8 +6,18 @@ namespace Misaki.HighPerformance.LowLevel.Buffer;
/// A dynamic memory management structure that automatically grows by creating linked arenas when more space is needed.
/// </summary>
[StructLayout(LayoutKind.Explicit, Size = 128)]
public unsafe struct DynamicArena : IDisposable
public unsafe struct DynamicArena : IMemoryAllocator<DynamicArena, DynamicArena.CreateOptions>
{
public struct CreateOptions
{
public uint initialSize;
}
public static DynamicArena Create(in CreateOptions options)
{
return new DynamicArena(options.initialSize);
}
[StructLayout(LayoutKind.Sequential)]
private struct ArenaNode
{
@@ -133,6 +143,10 @@ public unsafe struct DynamicArena : IDisposable
return result;
}
public readonly void Free(void* ptr)
{
}
/// <summary>
/// Resets all arenas in the chain.
/// </summary>