Update memory allocation practices and clean up code
Changed the `ParallelNoiseBenchmark` class to use `AllocationOption.None` for `UnsafeArray<float>` instances. Changed the `AllocationOption` enum to replace `UnInitialized` with `None` and clarified the `UnTracked` option. Changed constructors for `UnsafeArray<T>`, `UnsafeList<T>`, `UnsafeQueue<T>`, and `UnsafeStack<T>` to use `AllocationOption.None`. Changed the `HashMapHelper<TKey>` constructor to accept an `AllocationOption` parameter for improved flexibility. Changed the `Allocate` method documentation in `Arena.cs` to clarify memory management. Improved the `AllocationManager` class with a default arena size and updated allocation logic to handle new `AllocationOption` flags. Removed the import statement for `BenchmarkDotNet.Running` in `Program.cs` and added new imports for `Misaki.HighPerformance.Unsafe.Collections` and `Misaki.HighPerformance.Unsafe.Services`. Added a new `UnsafeArray<int>` in `Program.cs` and called `AllocationManager.Dispose()` to clean up resources.
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using Misaki.HighPerformance.Unsafe.Collections;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Misaki.HighPerformance.Unsafe.Buffer;
|
||||
|
||||
@@ -24,13 +23,14 @@ public unsafe struct Arena : IDisposable
|
||||
/// <summary>
|
||||
/// Allocates a block of memory of a specified size with a given alignment. Returns a pointer to the allocated
|
||||
/// memory or null if allocation fails.
|
||||
/// Must use <see cref="NativeMemory.AlignedFree"/> to free the memory.
|
||||
/// You don't need to free the memory manually, it will be freed when the arena is disposed.
|
||||
/// </summary>
|
||||
/// <param name="size">Specifies the amount of memory to allocate in bytes.</param>
|
||||
/// <param name="alignSize">Defines the alignment requirement for the allocated memory.</param>
|
||||
/// <param name="allocationOption">The option when allocating memory.</param>
|
||||
/// <returns>A pointer to the allocated memory block or null if the allocation cannot be fulfilled.</returns>
|
||||
/// <exception cref="ObjectDisposedException">Thrown if the arena has been disposed.</exception>
|
||||
public void* Allocate(uint size, uint alignSize, AllocationOption allocationType)
|
||||
public void* Allocate(uint size, uint alignSize, AllocationOption allocationOption)
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||
|
||||
@@ -43,7 +43,7 @@ public unsafe struct Arena : IDisposable
|
||||
_offset = offset + size;
|
||||
var ptr = _buffer + offset;
|
||||
|
||||
if (allocationType == AllocationOption.Clear)
|
||||
if (allocationOption.HasFlag(AllocationOption.Clear))
|
||||
{
|
||||
MemClear(ptr, size);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user