Enhance noise generation and memory management

Added new noise generation methods in `ParallelNoiseBenchmark`, including `Frac`, `Lerp`, and `GradientNoiseDirect`, and updated the `GradientNoise` method to utilize them. Changed constants to use `_LENGTH` for consistency.

Changed `Arena` and `DynamicArena` classes to use `uint` instead of `ulong` for size fields, improving memory usage. Updated memory allocation to use `NativeMemory` for better performance and safety.

Updated `UnsafeArray<T>` and `UnsafeList<T>` classes to replace `Marshal` methods with `NativeMemory`, enhancing performance and safety. Modified `Dispose` methods to use `NativeMemory.AlignedFree`.

Added `MemoryUtilities` class with new methods for memory management, including `MemClear`, `MemSet`, `MemCpy`, `SizeOf`, and `AlignOf`, utilizing `NativeMemory`.

Fixed minor cleanup in the `ObjectPool` class's `Dispose` method.
This commit is contained in:
2025-03-25 09:49:49 +09:00
parent aa1e9e6b1d
commit 7bcd699eb9
7 changed files with 120 additions and 73 deletions

View File

@@ -78,7 +78,7 @@ public unsafe struct UnsafeArray<T> : IUnsafeCollection<T>, IEnumerable<T> where
public UnsafeArray(int size, AllocationType allocationType)
{
_size = size;
_buffer = (T*)Marshal.AllocHGlobal(size * sizeof(T)).ToPointer();
_buffer = (T*)NativeMemory.AlignedAlloc((nuint)(size * sizeof(T)), (nuint)AlignOf<T>());
if (allocationType == AllocationType.Clear)
{
@@ -93,7 +93,7 @@ public unsafe struct UnsafeArray<T> : IUnsafeCollection<T>, IEnumerable<T> where
return;
}
_buffer = (T*)Marshal.ReAllocHGlobal((IntPtr)_buffer, newSize * sizeof(T)).ToPointer();
_buffer = (T*)NativeMemory.AlignedRealloc(_buffer, (nuint)(newSize * sizeof(T)), (nuint)AlignOf<T>());
_size = newSize;
}
@@ -105,7 +105,7 @@ public unsafe struct UnsafeArray<T> : IUnsafeCollection<T>, IEnumerable<T> where
public void Dispose()
{
Marshal.FreeHGlobal((IntPtr)_buffer);
NativeMemory.AlignedFree(_buffer);
_buffer = null;
_size = 0;