daily update on 20240312 by nitload youmu
This commit is contained in:
@@ -11,33 +11,6 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
//TODO 发现一个大问题,paramQueue大多数时候取出的是数组,不是数组句柄,也就是说其内存将被长期固定且不能回收,这是内存泄漏
|
||||
public unsafe class glArrayHandle
|
||||
{
|
||||
internal readonly Array copy;
|
||||
internal GCHandle handle;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public IntPtr AddressOfArray()
|
||||
{
|
||||
return handle.AddrOfPinnedObject();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static glArrayHandle Alloc<T>(T[] array) where T : struct
|
||||
{
|
||||
Array copy = new T[array.Length];
|
||||
array.CopyTo(copy, 0);
|
||||
return new glArrayHandle(copy);
|
||||
}
|
||||
|
||||
internal glArrayHandle(Array array)
|
||||
{
|
||||
copy = array;
|
||||
handle = GCHandle.Alloc(array, GCHandleType.Pinned);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A handle to an OpenGL object,
|
||||
/// must be indexed from a <see cref="glHandleSet"/>.
|
||||
@@ -139,7 +112,7 @@ namespace StgSharp.Graphics
|
||||
|
||||
public static glSHandle Zero
|
||||
{
|
||||
get { return Alloc(1); }
|
||||
get { return Alloc(0); }
|
||||
}
|
||||
|
||||
internal int DirectValue
|
||||
@@ -157,6 +130,52 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
}
|
||||
|
||||
//TODO 发现一个大问题,paramQueue大多数时候取出的是数组,不是数组句柄,也就是说其内存将被长期固定且不能回收,这是内存泄漏
|
||||
public unsafe class glArrayHandle
|
||||
{
|
||||
internal readonly Array a;
|
||||
internal GCHandle handle;
|
||||
|
||||
internal glArrayHandle(Array array)
|
||||
{
|
||||
this.a = array;
|
||||
handle = GCHandle.Alloc(array, GCHandleType.Pinned);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static glArrayHandle CopyAlloc<T>(T[] array) where T : struct
|
||||
{
|
||||
Array copy = new T[array.Length];
|
||||
array.CopyTo(copy, 0);
|
||||
return new glArrayHandle(copy);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static glArrayHandle Alloc<T>(T[] array) where T : struct
|
||||
{
|
||||
return new glArrayHandle(array);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public IntPtr AddressOfArray()
|
||||
{
|
||||
if (handle != default)
|
||||
{
|
||||
return handle.AddrOfPinnedObject();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
public void Release()
|
||||
{
|
||||
handle.Free();
|
||||
handle = default;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A handle to an OpenGL object.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user