Files
Misaki.HighPerformance/Misaki.HighPerformance.Test/UnitTest/Buffer/TestAllocationManager.cs
Misaki 9c4faa107a feat(memory): transition to AllocationHandle API
Replaced the deprecated Allocator API with the new AllocationHandle API across the codebase. Updated constructors, methods, and tests to use AllocationHandle for memory management. Marked Allocator-based methods as [Obsolete] and provided alternatives.

Added OwnershipTransferAnalyzer to detect ownership transfer issues and introduced OwnershipTransferAttribute for marking parameters. Enhanced DefensiveCopyAnalyzer with additional checks for readonly and ValueType instances.

Refactored internal memory management in AllocationManager and updated benchmarks, utilities, and documentation to reflect the changes.

BREAKING CHANGE: Deprecated Allocator API in favor of AllocationHandle. Updated constructors and methods to use AllocationHandle. Users must migrate to the new API.
2026-04-12 17:50:12 +09:00

84 lines
2.0 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);
}
[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 unsafe void StackAllocationTest()
{
var thread = new Thread(() =>
{
var scope = AllocationManager.CreateStackScope();
var ptr1 = new MemoryBlock(1024, 8, scope.AllocationHandle);
Assert.IsTrue(ptr1.IsCreated);
ptr1.Dispose();
scope.Dispose();
});
thread.Start();
var scope = AllocationManager.CreateStackScope();
var ptr2 = new MemoryBlock(1024, 8, scope.AllocationHandle);
Assert.IsTrue(ptr2.IsCreated);
ptr2.Dispose();
scope.Dispose();
thread.Join();
}
}