mirror of
https://github.com/mirror/processhacker
synced 2026-06-08 16:03:24 +00:00
3a9a6e8305
git-svn-id: svn://svn.code.sf.net/p/processhacker/code@4764 21ef857c-d57f-4fe0-8362-d861dc6d29cd
33 lines
684 B
C#
33 lines
684 B
C#
using System;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace ProcessHacker.Native
|
|
{
|
|
public sealed class PinnedObject<T> : MemoryRegion
|
|
{
|
|
private readonly T _object;
|
|
private GCHandle _handle;
|
|
|
|
public PinnedObject(T obj)
|
|
{
|
|
_object = obj;
|
|
_handle = GCHandle.Alloc(obj, GCHandleType.Pinned);
|
|
}
|
|
|
|
protected override void Free()
|
|
{
|
|
_handle.Free();
|
|
}
|
|
|
|
public IntPtr Address
|
|
{
|
|
get { return _handle.AddrOfPinnedObject(); }
|
|
}
|
|
|
|
public T Object
|
|
{
|
|
get { return _object; }
|
|
}
|
|
}
|
|
}
|