Upgrade to .net9
This commit is contained in:
parent
eb97cfb57c
commit
a1cb6592eb
15 changed files with 395 additions and 54 deletions
37
Infra/Buffers/ImmovableMemory.cs
Normal file
37
Infra/Buffers/ImmovableMemory.cs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
using System.Buffers;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StitchATon2.Infra.Buffers;
|
||||
|
||||
internal sealed unsafe class ImmovableMemory<T> : MemoryManager<T> where T : unmanaged
|
||||
{
|
||||
private readonly T* _pointer;
|
||||
private readonly int _length;
|
||||
private bool _disposed;
|
||||
|
||||
public ImmovableMemory(int count)
|
||||
{
|
||||
_pointer = (T*)NativeMemory.Alloc((nuint)count, (nuint)Unsafe.SizeOf<T>());
|
||||
_length = count;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (!_disposed)
|
||||
{
|
||||
NativeMemory.Free(_pointer);
|
||||
_disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override Span<T> GetSpan()
|
||||
=> new(_pointer, _length);
|
||||
|
||||
public override MemoryHandle Pin(int elementIndex = 0)
|
||||
=> new(_pointer + elementIndex);
|
||||
|
||||
public override void Unpin()
|
||||
{
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue