Library to make working with native memory less of a pain.
$ dotnet add package NativeMemoryNativeArray<T>: Access native data
NativeArrayPool<T>: Just like ArrayPool, pools native arrays
INativeAllocator
HGlobalMemAllocator: Allocates memory using Marshal.AllocHGlobalCoTaskMemAllocator: Marshal.AllocCoTaskMemUsing the ArrayPool:
// allocates a new array with 10 bytes
var array = new NativeArray<byte>(10);
array.Dispose();
// Borrow an array of 200 bytes
array = NativeArrayPool<byte>.SharedHGlobal.Rent(200);
// Return the array to the pool.
NativeArrayPool<byte>.SharedHGlobal.Return(array);
// Borrow an array of 200 bytes and return it using the dispose pattern.
using (array = NativeArrayPool<byte>.SharedHGlobal.Rent(200))
{
}
Special thanks to the guys from Poltergeist, where i mostly stole this code got my inspiration from.