Files
Misaki.HighPerformance/Misaki.HighPerformance.Test/UnitTest/Collections/TestUnsafeArray.cs
Misaki fbe72e33f7 Refactor AllocationManager and enhance debug tracking
Refactored `AllocationManager` to introduce intrusive allocation tracking with `AllocationHeader` structs for debug mode. Added lightweight allocation counters for non-debug mode. Enhanced memory leak detection with detailed stack traces and `MemoryLeakException`.

Simplified `AllocationInfo` by removing the `Allocator` property. Updated `AllocationOption` enum to remove `UnTracked` and clarified documentation.

Improved unsafe collections (`UnsafeArray`, `UnsafeStack`, etc.) with strongly-typed enumerators and better compatibility with `IEnumerable<T>`. Enhanced `UnsafeStack` with a dedicated `Enumerator` struct and consistent constructor parameters.

Refactored `MemoryLeakException` to support detailed allocation info and improved stack trace formatting. Simplified `MemoryUtility` by removing redundant null checks.

Added unit tests for `AllocationManager`, `UnsafeArray`, and `UnsafeStack` to validate memory management and functionality. Updated `Program.cs` with new examples.

Cleaned up namespaces, removed redundant `using` directives, and improved XML documentation. Applied `MethodImplOptions.AggressiveInlining` to performance-critical methods.
2025-11-06 01:28:43 +09:00

56 lines
1.1 KiB
C#

using Misaki.HighPerformance.LowLevel.Buffer;
using Misaki.HighPerformance.LowLevel.Collections;
namespace Misaki.HighPerformance.Test.UnitTest.Collections;
[TestClass]
public class TestUnsafeArray
{
private UnsafeArray<int> _arr;
[TestInitialize]
public void Initialize()
{
_arr = new UnsafeArray<int>(16, Allocator.Persistent);
}
[TestCleanup]
public void Cleanup()
{
_arr.Dispose();
}
[TestMethod]
public void TestIndexAccess()
{
for (int i = 0; i < _arr.Count; i++)
{
_arr[i] = i * 10;
}
for (int i = 0; i < _arr.Count; i++)
{
Assert.AreEqual(i * 10, _arr[i]);
}
}
[TestMethod]
public void TestEnumeration()
{
_arr.Clear();
int expectedValue = 0;
foreach (var item in _arr)
{
Assert.AreEqual(expectedValue, item);
}
}
[TestMethod]
public void TestIsCreated()
{
Assert.IsTrue(_arr.IsCreated);
_arr.Dispose();
Assert.IsFalse(_arr.IsCreated);
}
}