diff --git a/src/IAllocator.cs b/src/IAllocator.cs index 5834206..09995e8 100644 --- a/src/IAllocator.cs +++ b/src/IAllocator.cs @@ -4,5 +4,5 @@ public unsafe interface IAllocator { public T* Allocate(long count) where T : unmanaged; public void Free(T* pointer) where T : unmanaged; - public T* Realloc(T* pointer, long count) where T : unmanaged; -} + public T* Reallocate(T* pointer, long count) where T : unmanaged; +} \ No newline at end of file diff --git a/src/NativeAllocator.cs b/src/NativeAllocator.cs new file mode 100644 index 0000000..3a1dbb9 --- /dev/null +++ b/src/NativeAllocator.cs @@ -0,0 +1,22 @@ +using System.Runtime.InteropServices; + +namespace SharpAllocators +{ + public readonly unsafe struct NativeAllocator : IAllocator + { + public T* Allocate(long count) where T : unmanaged + { + return (T*)NativeMemory.Alloc((nuint)count); + } + + public void Free(T* pointer) where T : unmanaged + { + NativeMemory.Free(pointer); + } + + public T* Reallocate(T* pointer, long count) where T : unmanaged + { + return (T*)NativeMemory.Realloc(pointer, (nuint)count); + } + } +}