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