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:
@@ -7,8 +7,18 @@ namespace Misaki.HighPerformance.LowLevel.Buffer;
|
||||
/// A memory management structure that allocates and resets memory blocks with specified alignment.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Explicit, Size = 64)] // Cache line aligned to prevent false sharing
|
||||
public unsafe struct Arena : IDisposable
|
||||
public unsafe struct Arena : IMemoryAllocator<Arena, Arena.CreateOptions>
|
||||
{
|
||||
public struct CreateOptions
|
||||
{
|
||||
public nuint size;
|
||||
}
|
||||
|
||||
public static Arena Create(in CreateOptions opts)
|
||||
{
|
||||
return new Arena(opts.size);
|
||||
}
|
||||
|
||||
[FieldOffset(0)]
|
||||
private byte* _buffer;
|
||||
[FieldOffset(8)]
|
||||
@@ -82,6 +92,11 @@ public unsafe struct Arena : IDisposable
|
||||
return ptr;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly void Free(void* ptr)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the arena.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user