Refactored thread-local stack allocator in AllocationManager to use ThreadLocalStackPool, removing global stack pointer arrays and locks. In FreeList, replaced fixed-size cache array and maxConcurrencyLevel with a dynamic linked-list system using SharedState and CacheReclaimer for thread cache lifecycle management. Block headers now store cache pointers instead of indices. Updated allocation/free logic and tests accordingly. Bumped assembly version to 3.1.3.
90 lines
2.2 KiB
C#
90 lines
2.2 KiB
C#
using Misaki.HighPerformance.LowLevel.Buffer;
|
|
|
|
namespace Misaki.HighPerformance.Test.UnitTest.Buffer;
|
|
|
|
[TestClass]
|
|
[DoNotParallelize]
|
|
public class TestAllocationManager
|
|
{
|
|
[TestMethod]
|
|
public void PersistentAllocationTest()
|
|
{
|
|
var ptr1 = new MemoryBlock(1024, 8, AllocationHandle.Persistent);
|
|
var ptr2 = new MemoryBlock(2048, 8, AllocationHandle.Persistent);
|
|
|
|
Assert.IsTrue(ptr1.IsCreated);
|
|
Assert.IsTrue(ptr2.IsCreated);
|
|
|
|
ptr1.Dispose();
|
|
ptr2.Dispose();
|
|
|
|
Assert.IsFalse(ptr1.IsCreated);
|
|
Assert.IsFalse(ptr2.IsCreated);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TempAllocationTest()
|
|
{
|
|
var ptr1 = new MemoryBlock(1024, 8, AllocationHandle.Temp);
|
|
var ptr2 = new MemoryBlock(2048, 8, AllocationHandle.Temp);
|
|
|
|
Assert.IsTrue(ptr1.IsCreated);
|
|
Assert.IsTrue(ptr2.IsCreated);
|
|
|
|
ptr1.Dispose();
|
|
ptr2.Dispose();
|
|
|
|
Assert.IsFalse(ptr1.IsCreated);
|
|
Assert.IsFalse(ptr2.IsCreated);
|
|
|
|
AllocationManager.ResetTempAllocator();
|
|
}
|
|
|
|
[TestMethod]
|
|
public void FreeListAllocationTest()
|
|
{
|
|
var ptr1 = new MemoryBlock(1024, 8, AllocationHandle.FreeList);
|
|
var ptr2 = new MemoryBlock(2048, 8, AllocationHandle.FreeList);
|
|
|
|
Assert.IsTrue(ptr1.IsCreated);
|
|
Assert.IsTrue(ptr2.IsCreated);
|
|
|
|
ptr1.Dispose();
|
|
ptr2.Dispose();
|
|
|
|
Assert.IsFalse(ptr1.IsCreated);
|
|
Assert.IsFalse(ptr2.IsCreated);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void StackAllocationTest()
|
|
{
|
|
var thread = new Thread(() =>
|
|
{
|
|
var scope = AllocationManager.CreateStackScope();
|
|
var ptr1 = new MemoryBlock(1024, 8, scope.AllocationHandle);
|
|
|
|
Assert.IsTrue(ptr1.IsCreated);
|
|
|
|
Thread.Sleep(100); // Simulate some work
|
|
|
|
ptr1.Dispose();
|
|
scope.Dispose();
|
|
});
|
|
|
|
thread.Start();
|
|
|
|
var scope = AllocationManager.CreateStackScope();
|
|
Assert.AreEqual(0u, scope.OriginalOffset);
|
|
|
|
var ptr2 = new MemoryBlock(1024, 8, scope.AllocationHandle);
|
|
|
|
Assert.IsTrue(ptr2.IsCreated);
|
|
|
|
ptr2.Dispose();
|
|
scope.Dispose();
|
|
|
|
thread.Join();
|
|
}
|
|
}
|