diff --git a/Misaki.HighPerformance.LowLevel/Buffer/AllocationManager.cs b/Misaki.HighPerformance.LowLevel/Buffer/AllocationManager.cs index 83c2419..2b0b765 100644 --- a/Misaki.HighPerformance.LowLevel/Buffer/AllocationManager.cs +++ b/Misaki.HighPerformance.LowLevel/Buffer/AllocationManager.cs @@ -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 } + /// + /// Gets the total newSize of all currently tracked allocations. + /// + /// + /// Always returns 0 if MHP_ENABLE_SAFETY_CHECKS is disabled. + /// + /// The total newSize of all currently tracked allocations. + 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 + } + /// /// Disposes of the AllocationManager, freeing all allocated memory and resources. /// diff --git a/Misaki.HighPerformance.LowLevel/Collections/HashMapHelper.cs b/Misaki.HighPerformance.LowLevel/Collections/HashMapHelper.cs index 1cca1db..9741167 100644 --- a/Misaki.HighPerformance.LowLevel/Collections/HashMapHelper.cs +++ b/Misaki.HighPerformance.LowLevel/Collections/HashMapHelper.cs @@ -719,6 +719,7 @@ public unsafe struct HashMapHelper : IDisposable { if (!IsCreated) { + Debug.Fail("The UnsafeArray is not created or already disposed."); return; } diff --git a/Misaki.HighPerformance.LowLevel/Collections/UnTypedArray.cs b/Misaki.HighPerformance.LowLevel/Collections/UnTypedArray.cs index fb43d56..136e084 100644 --- a/Misaki.HighPerformance.LowLevel/Collections/UnTypedArray.cs +++ b/Misaki.HighPerformance.LowLevel/Collections/UnTypedArray.cs @@ -1,6 +1,7 @@ using Misaki.HighPerformance.LowLevel.Buffer; using Misaki.HighPerformance.LowLevel.Collections.Contracts; using Misaki.HighPerformance.LowLevel.Utilities; +using System.Diagnostics; using System.Runtime.CompilerServices; namespace Misaki.HighPerformance.LowLevel.Collections; @@ -272,6 +273,7 @@ public unsafe struct UnTypedArray : IUnTypedCollection { if (!IsCreated) { + Debug.Fail("The UnsafeArray is not created or already disposed."); return; } diff --git a/Misaki.HighPerformance.LowLevel/Collections/UnsafeArray.cs b/Misaki.HighPerformance.LowLevel/Collections/UnsafeArray.cs index b0e82a7..4143ec0 100644 --- a/Misaki.HighPerformance.LowLevel/Collections/UnsafeArray.cs +++ b/Misaki.HighPerformance.LowLevel/Collections/UnsafeArray.cs @@ -418,6 +418,7 @@ public unsafe struct UnsafeArray : IUnsafeCollection { if (!IsCreated) { + Debug.Fail("The UnsafeArray is not created or already disposed."); return; } diff --git a/Misaki.HighPerformance.LowLevel/Collections/UnsafeList.cs b/Misaki.HighPerformance.LowLevel/Collections/UnsafeList.cs index 9cf5ab9..be69dfc 100644 --- a/Misaki.HighPerformance.LowLevel/Collections/UnsafeList.cs +++ b/Misaki.HighPerformance.LowLevel/Collections/UnsafeList.cs @@ -363,15 +363,6 @@ public unsafe struct UnsafeList : IUnsafeCollection _count += values.Length; } - /// - /// Adds a range of elements to the collection. - /// - /// A collection containing the elements to add. - public void AddRange(ReadOnlyUnsafeCollection collection) - { - AddRange((T*)collection.GetUnsafePtr(), collection.Count); - } - /// /// Adds a range of elements from a pointer to the collection. /// diff --git a/Misaki.HighPerformance.LowLevel/Misaki.HighPerformance.LowLevel.csproj b/Misaki.HighPerformance.LowLevel/Misaki.HighPerformance.LowLevel.csproj index a605db0..51f5c07 100644 --- a/Misaki.HighPerformance.LowLevel/Misaki.HighPerformance.LowLevel.csproj +++ b/Misaki.HighPerformance.LowLevel/Misaki.HighPerformance.LowLevel.csproj @@ -7,7 +7,7 @@ true true Misaki - 1.6.3 + 1.6.4 $(AssemblyVersion) https://git.personalnas.com/Misaki/Misaki.HighPerformance.git https://git.personalnas.com/Misaki/Misaki.HighPerformance.git diff --git a/Misaki.HighPerformance.Test/Program.cs b/Misaki.HighPerformance.Test/Program.cs index ce94a9c..b432621 100644 --- a/Misaki.HighPerformance.Test/Program.cs +++ b/Misaki.HighPerformance.Test/Program.cs @@ -15,6 +15,7 @@ AllocationManager.Initialize(opts); var arr = new UnsafeArray(10, Allocator.Persistent); var arrcpy = arr; arr.Dispose(); +arrcpy.Dispose(); Console.WriteLine(arr.IsCreated); Console.WriteLine(arrcpy.IsCreated);