Initial commit

This commit is contained in:
dennisarfan 2025-07-30 07:30:00 +07:00
commit ef3b7d68fb
30 changed files with 1568 additions and 0 deletions

View file

@ -0,0 +1,28 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace StitchATon2.Infra.Buffers;
internal sealed unsafe class UnmanagedMemory<T> : IBuffer<T> where T : unmanaged
{
private readonly void* _pointer;
private readonly int _count;
public ref T this[int index] => ref Unsafe.AsRef<T>((T*)_pointer + index); // *((T*)_pointer + index);
public Span<T> Span => new(_pointer, _count);
public UnmanagedMemory(int count)
{
_pointer = NativeMemory.Alloc((nuint)count, (nuint)Unsafe.SizeOf<T>());
_count = count;
}
~UnmanagedMemory() => Dispose();
public void Dispose()
{
NativeMemory.Free(_pointer);
GC.SuppressFinalize(this);
}
}