Refactor memory management in AllocationManager

Changed the `AllocationManager` to use `ThreadLocal<DynamicArena>` for thread-specific memory allocation.
Changed the `Initialize` method to directly validate `initialSize` and initialize the thread-local arena.
Changed the `Allocate` and `Realloc` methods to utilize the thread-local arena for memory operations.
Changed the `Free` method to remove unnecessary locking due to thread-local management.
Added a new private method `EnsureInitialized` to verify the initialization of the thread-local arena.
Added a public static method `ResetAll` to reset all thread-local arenas.
Changed the `ResetCurrent` method to reset only the current thread's arena.
Updated the `Dispose` method to clean up all thread-local arenas and clear the allocated dictionary.
Uncommented the `UNSAFE_COLLECTION_CHECK` directive for enhanced debugging checks in `AllocationManager`.
Changed `CollectionBenchmark` to call `AllocationManager.ResetCurrent()` after populating the `UnsafeArray<int>`.
This commit is contained in:
2025-04-11 16:41:28 +09:00
parent 691a336111
commit d306f183de
2 changed files with 49 additions and 36 deletions

View File

@@ -34,6 +34,7 @@ public unsafe class CollectionBenchmark
{
array[i] = i;
}
AllocationManager.ResetCurrent();
}
[Benchmark]