diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2019-04-05 14:13:20 +0200 |
|---|---|---|
| committer | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2019-04-05 14:13:20 +0200 |
| commit | 04d94de392b6e5ca4f82acc233df7b3f97abca36 (patch) | |
| tree | 27df9645ea97cf36c99cb4f8ed5f347cc00cb458 /vke/src/ExtensionMethods.cs | |
| parent | 7d305b07ccaeb2a8cd342e3395db46f2f8fffade (diff) | |
Activable pattern wip
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); + //} } } |