//[java.attr.RetainType] private java.util.concurrent.atomic.AtomicLong pinned; public static GCHandle Alloc(object value, System.Runtime.InteropServices.GCHandleType type) { var h = new GCHandle() { objref = value }; if (type == System.Runtime.InteropServices.GCHandleType.Pinned) { h.pinned = true; if (value != null) { var trackedObject = IdentifierWeakTable.Global.GetTrackedObject(value); h.handle = (trackedObject != null) ? trackedObject.id : IdentifierWeakTable.GlobalGenerate(value); //h.pinned = new java.util.concurrent.atomic.AtomicLong(); } } else if (type != System.Runtime.InteropServices.GCHandleType.Normal) { throw new System.PlatformNotSupportedException(); } return(h); }
public static GCHandle FromIntPtr(System.IntPtr value) { object obj = null; long intptr; if ((intptr = (long)value) != 0) { int id = (int)(intptr >> 32); /* * if (intptr != ((long) id) << 32) * throw new System.PlatformNotSupportedException("FromIntPtr"); */ obj = IdentifierWeakTable.GlobalGetObject(id); if (obj == null) { throw new System.PlatformNotSupportedException("FromIntPtr"); } } return(new GCHandle() { objref = obj }); }