This commit is contained in:
Connection Refused
2019-12-02 19:51:12 +08:00
commit b2ea730984
229 changed files with 86605 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
using System;
using System.Runtime.InteropServices;
namespace DnsClient
{
internal class DisposableIntPtr : IDisposable
{
public IntPtr Ptr => _ptr;
public bool IsValid { get; private set; } = true;
private IntPtr _ptr;
private DisposableIntPtr()
{
}
public static DisposableIntPtr Alloc(int size)
{
var ptr = new DisposableIntPtr();
try
{
ptr._ptr = Marshal.AllocHGlobal(size);
}
catch (OutOfMemoryException)
{
ptr.IsValid = false;
}
return ptr;
}
public void Dispose()
{
Marshal.FreeHGlobal(_ptr);
}
}
}