mirror of
https://git.743378673.xyz/MeloNX/MeloNX.git
synced 2025-06-29 11:56:24 +02:00
Move solution and projects to src
This commit is contained in:
parent
cd124bda58
commit
cee7121058
3466 changed files with 55 additions and 55 deletions
48
src/Ryujinx.Graphics.Vulkan/NativeArray.cs
Normal file
48
src/Ryujinx.Graphics.Vulkan/NativeArray.cs
Normal file
|
@ -0,0 +1,48 @@
|
|||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.Graphics.Vulkan
|
||||
{
|
||||
unsafe class NativeArray<T> : IDisposable where T : unmanaged
|
||||
{
|
||||
public T* Pointer { get; private set; }
|
||||
public int Length { get; }
|
||||
|
||||
public ref T this[int index]
|
||||
{
|
||||
get => ref Pointer[Checked(index)];
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private int Checked(int index)
|
||||
{
|
||||
if ((uint)index >= (uint)Length)
|
||||
{
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
public NativeArray(int length)
|
||||
{
|
||||
Pointer = (T*)Marshal.AllocHGlobal(checked(length * Unsafe.SizeOf<T>()));
|
||||
Length = length;
|
||||
}
|
||||
|
||||
public Span<T> AsSpan()
|
||||
{
|
||||
return new Span<T>(Pointer, Length);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (Pointer != null)
|
||||
{
|
||||
Marshal.FreeHGlobal((IntPtr)Pointer);
|
||||
Pointer = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue