diff options
Diffstat (limited to 'vke/src/ExtensionMethods.cs')
| -rw-r--r-- | vke/src/ExtensionMethods.cs | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/vke/src/ExtensionMethods.cs b/vke/src/ExtensionMethods.cs index 1cf01cd..620c379 100644 --- a/vke/src/ExtensionMethods.cs +++ b/vke/src/ExtensionMethods.cs @@ -62,6 +62,21 @@ namespace VKE { handles[obj].Free (); handles.Remove (obj); } - + public static IntPtr Pin<T> (this List<T> obj) { + if (handles.ContainsKey (obj)) + Debug.WriteLine ("Pinning already pinned object: {0}", obj); + + GCHandle hnd = GCHandle.Alloc (obj.ToArray(), GCHandleType.Pinned); + handles.Add (obj, hnd); + return hnd.AddrOfPinnedObject (); + } + //public static void Unpin<T> (this List<T> obj) { + // if (!handles.ContainsKey (obj)) { + // Debug.WriteLine ("Trying to unpin {0}, but object has not been pinned.", obj); + // return; + // } + // handles[obj].Free (); + // handles.Remove (obj); + //} } } |