Remove unused methods and project file

Removed the `CeilPow2` method and its associated using directive from `MathUtilities.cs`.
Removed the entire content of the `Misaki.HighPerformance.Mathematics.csproj` file.

Added new classes and structures

Added a new `MemoryLeakException` class to handle memory leak reporting in `MemoryLeakException.cs`.
Added a new `AllocationInfo` struct to store allocation details in `AllocationManager.cs`.

Changed memory management logic

Changed memory allocation handling in `Program.cs` by introducing `unfreeArray` and `unfreeList`.
Changed the `_allocated` dictionary in `AllocationManager.cs` from `UnsafeHashMap` to `Dictionary` and updated allocation logic to store `AllocationInfo`.
Modified allocation and reallocation logic in `AllocationManager` to include stack trace information in debug mode.
Updated disposal logic in `AllocationManager` to throw a `MemoryLeakException` for unfreed allocations.
This commit is contained in:
2025-04-03 22:55:48 +09:00
parent 791be1bed2
commit 9eea53d8f1
5 changed files with 94 additions and 39 deletions

View File

@@ -0,0 +1,49 @@
using Misaki.HighPerformance.Unsafe.Services;
using System.Diagnostics;
using System.Text;
namespace Misaki.HighPerformance.Unsafe;
internal class MemoryLeakException(params AllocationInfo[] Infos) : Exception
{
private static string GetMessage(StackTrace? stackTrace)
{
if (stackTrace == null)
{
return "No stack trace available.";
}
var stringBuilder = new StringBuilder();
stringBuilder.AppendLine("Memory leak detected at: ");
for (var i = 0; i < stackTrace.FrameCount; i++)
{
var frame = stackTrace.GetFrame(i);
if (frame != null)
{
stringBuilder.AppendLine($"File: {frame.GetFileName()}, Line: {frame.GetFileLineNumber()}");
}
}
return stringBuilder.ToString();
}
public override string Message
{
get
{
#if DEBUG
var stringBuilder = new StringBuilder();
stringBuilder.AppendLine($"Found {Infos.Length} memory lakes!");
foreach (var info in Infos)
{
stringBuilder.AppendLine(GetMessage(info.StackTrace));
}
return stringBuilder.ToString();
#else
return $"There are still {Infos.Length} buffers that hold {Infos.Sum(i => (uint)i.Size)} bytes in total are not freed yet. Please free them before disposing. Switch to debug mode for more information.";
#endif
}
}
}