From 28341180cb3c19708a9e16bf8019dd856f0f56fc Mon Sep 17 00:00:00 2001 From: Viktor Stojanovic Date: Sun, 2 Aug 2026 21:24:06 +0200 Subject: [PATCH 1/3] Add NativeAllocator --- src/NativeAllocator.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/NativeAllocator.cs diff --git a/src/NativeAllocator.cs b/src/NativeAllocator.cs new file mode 100644 index 0000000..92c9086 --- /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* Realloc(T* pointer, long count) where T : unmanaged + { + return (T*)NativeMemory.Realloc(pointer, (nuint)count); + } + } +} From 80a0c9a73f2328c17827526ecddbd2105ed133e8 Mon Sep 17 00:00:00 2001 From: Viktor Stojanovic Date: Sun, 2 Aug 2026 21:28:46 +0200 Subject: [PATCH 2/3] Rename Realloc to Reallocate --- src/IAllocator.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/IAllocator.cs b/src/IAllocator.cs index 8d6232e..09995e8 100644 --- a/src/IAllocator.cs +++ b/src/IAllocator.cs @@ -2,7 +2,7 @@ public unsafe interface IAllocator { - public T* Allocate() where T : unmanaged; + public T* Allocate(long count) where T : unmanaged; public void Free(T* pointer) where T : unmanaged; - public T* Realloc(T* pointer, long size) where T : unmanaged; -} + public T* Reallocate(T* pointer, long count) where T : unmanaged; +} \ No newline at end of file From 9b919ddc92d4682bfa3f16dba434ff15a1ff8ea5 Mon Sep 17 00:00:00 2001 From: Viktor Stojanovic Date: Sun, 2 Aug 2026 21:28:58 +0200 Subject: [PATCH 3/3] Add NativeAllocator --- src/NativeAllocator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NativeAllocator.cs b/src/NativeAllocator.cs index 92c9086..3a1dbb9 100644 --- a/src/NativeAllocator.cs +++ b/src/NativeAllocator.cs @@ -14,7 +14,7 @@ public void Free(T* pointer) where T : unmanaged NativeMemory.Free(pointer); } - public T* Realloc(T* pointer, long count) where T : unmanaged + public T* Reallocate(T* pointer, long count) where T : unmanaged { return (T*)NativeMemory.Realloc(pointer, (nuint)count); }