12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- using System;
- using System.Runtime.InteropServices;
- namespace UTJ.FbxExporter
- {
- public class PinnedObject<T> : IDisposable
- {
- public PinnedObject(T data)
- {
- this.m_data = data;
- this.m_gch = GCHandle.Alloc(this.m_data, GCHandleType.Pinned);
- }
- public T Object
- {
- get
- {
- return this.m_data;
- }
- }
- public IntPtr Pointer
- {
- get
- {
- return this.m_gch.AddrOfPinnedObject();
- }
- }
- public void Dispose()
- {
- this.Dispose(true);
- GC.SuppressFinalize(this);
- }
- protected virtual void Dispose(bool disposing)
- {
- if (disposing && this.m_gch.IsAllocated)
- {
- this.m_gch.Free();
- }
- }
- public static implicit operator IntPtr(PinnedObject<T> v)
- {
- return v.Pointer;
- }
- public static implicit operator T(PinnedObject<T> v)
- {
- return v.Object;
- }
- private T m_data;
- private GCHandle m_gch;
- }
- }
|