Replaced `SafeHandle` with a new `MemoryHandle` system for improved memory tracking, safety, and leak detection. Updated allocators (`ArenaAllocator`, `HeapAllocator`, `StackAllocator`) and collections (`UnTypedArray`, `UnsafeArray<T>`, `UnsafeBitSet`) to use `MemoryHandle`. Refactored `AllocationManager` to use `ConcurrentSlotMap` for live allocation tracking and added methods for managing `MemoryHandle` instances. Simplified alignment and padding logic across allocators and collections. Enhanced performance with optimized memory operations (`MemClear`, `MemSet`, `MemCpy`) and vectorized operations in `MemoryUtility` and `UnsafeBitSet`. Fixed alignment issues in vectorized memory operations. Updated tests to reflect the new memory management system and added new tests for `UnsafeBitSet` bitwise operations. Enabled `ENABLE_COLLECTION_CHECKS` for debug builds and improved error messages and documentation. Removed unused `SafeHandle` code and adjusted project configuration to include necessary references.
61 lines
1.4 KiB
C#
61 lines
1.4 KiB
C#
using Misaki.HighPerformance.LowLevel;
|
|
using Misaki.HighPerformance.LowLevel.Buffer;
|
|
using Misaki.HighPerformance.LowLevel.Collections;
|
|
|
|
namespace Misaki.HighPerformance.Test.UnitTest.Buffer;
|
|
|
|
[TestClass]
|
|
public class TestAllocationManager
|
|
{
|
|
[TestInitialize]
|
|
public void Initialize()
|
|
{
|
|
AllocationManager.EnableDebugLayer();
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ShouldNotLeakTest()
|
|
{
|
|
try
|
|
{
|
|
var array = new UnsafeArray<int>(10, Allocator.Persistent);
|
|
var array2 = new UnsafeArray<int>(10, Allocator.Persistent);
|
|
|
|
array.Dispose();
|
|
array2.Dispose();
|
|
|
|
AllocationManager.Dispose();
|
|
}
|
|
finally
|
|
{
|
|
var leaks = AllocationManager.LiveAllocationCount;
|
|
Assert.AreEqual(0, leaks);
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ShouldLeakTest()
|
|
{
|
|
var array = new UnsafeArray<int>(10, Allocator.Persistent);
|
|
var array2 = new UnsafeArray<int>(10, Allocator.Persistent);
|
|
|
|
try
|
|
{
|
|
AllocationManager.Dispose();
|
|
}
|
|
catch (MemoryLeakException)
|
|
{
|
|
var leaks = AllocationManager.LiveAllocationCount;
|
|
Assert.AreEqual(2, leaks);
|
|
|
|
return;
|
|
}
|
|
finally
|
|
{
|
|
array.Dispose();
|
|
array2.Dispose();
|
|
}
|
|
|
|
Assert.Fail("Expected MemoryLeakException was not thrown.");
|
|
}
|
|
} |