mirror of
https://github.com/gwdevhub/Daybreak.git
synced 2026-07-18 00:29:48 +00:00
23 lines
535 B
C#
23 lines
535 B
C#
using System.Runtime.InteropServices;
|
|
|
|
namespace Daybreak.API.Interop;
|
|
|
|
public sealed class UnmanagedStruct<T> : IDisposable
|
|
where T : struct
|
|
{
|
|
public nint Address { get; private set; }
|
|
|
|
public UnmanagedStruct(T value)
|
|
{
|
|
this.Address = Marshal.AllocHGlobal(Marshal.SizeOf<T>());
|
|
Marshal.StructureToPtr(value, this.Address, false);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
Marshal.DestroyStructure<T>(this.Address);
|
|
Marshal.FreeHGlobal(this.Address);
|
|
this.Address = 0x0;
|
|
}
|
|
}
|