Refactor to use MHP_ENABLE_SAFETY_CHECKS, MHP_ENABLE_STACKTRACE, and MHP_ENABLE_MIMALLOC for feature toggling. Remove FreeList allocator in JobSchedular and debug-layer code, simplifying memory management. Improve memory leak detection and reporting, update memory allocation API, and guard all safety/debug features with new defines. Update csproj files, README, and code samples to match new API and toggles. Fix and improve collection types for correct behavior with and without safety checks. The codebase is now more modular and easier to configure for different build environments. BREAKING CHANGE: Old defines (ENABLE_SAFETY_CHECKS, ENABLE_DEBUG_LAYER, ENABLE_MIMALLOC) are replaced with MHP_* equivalents. FreeList allocator and related debug features are removed. Some APIs and behaviors have changed for safety/debug configuration.
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
|
|
{
|
|
[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
|
|
{
|
|
#if MHP_ENABLE_SAFETY_CHECKS
|
|
var leaks = AllocationManager.LiveAllocationCount;
|
|
Assert.AreEqual(0, leaks);
|
|
#endif
|
|
}
|
|
}
|
|
|
|
[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)
|
|
{
|
|
#if MHP_ENABLE_SAFETY_CHECKS
|
|
var leaks = AllocationManager.LiveAllocationCount;
|
|
Assert.AreEqual(2, leaks);
|
|
#endif
|
|
|
|
return;
|
|
}
|
|
finally
|
|
{
|
|
array.Dispose();
|
|
array2.Dispose();
|
|
}
|
|
|
|
#if ENABLE_SAFETY_CHECKS
|
|
Assert.Fail("Expected MemoryLeakException was not thrown.");
|
|
#endif
|
|
}
|
|
} |