feat(buffer): add allocation tracking and diagnostics
Add AllocationManager.GetTotalAllocatedMemory() to track total allocations when safety checks are enabled. Improve diagnostics by calling Debug.Fail in Dispose methods of HashMapHelper, UnTypedArray, and UnsafeArray when disposing uninitialized or already disposed arrays. Remove AddRange(ReadOnlyUnsafeCollection<T>) from UnsafeList<T>. Increment assembly version to 1.6.4. Ensure arrcpy is disposed in Program.cs.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#if MHP_ENABLE_SAFETY_CHECKS
|
||||
using Misaki.HighPerformance.Collections;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
#endif
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
@@ -804,6 +806,30 @@ public static unsafe class AllocationManager
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the total newSize of all currently tracked allocations.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Always returns 0 if MHP_ENABLE_SAFETY_CHECKS is disabled.
|
||||
/// </remarks>
|
||||
/// <returns>The total newSize of all currently tracked allocations.</returns>
|
||||
public static nuint GetTotalAllocatedMemory()
|
||||
{
|
||||
#if MHP_ENABLE_SAFETY_CHECKS
|
||||
Debug.Assert(s_initialized, "AllocationManager is not initialized.");
|
||||
|
||||
nuint total = 0;
|
||||
foreach (var allocation in s_allocations)
|
||||
{
|
||||
total += allocation.Size;
|
||||
}
|
||||
|
||||
return total;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disposes of the AllocationManager, freeing all allocated memory and resources.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user