c#获取对象指针&从指针转为对象

GCHandle objHandle = GCHandle.Alloc(Globals.Instance.BlackBoard, GCHandleType.WeakTrackResurrection);
int address = GCHandle.ToIntPtr(objHandle).ToInt32();

Object obj = GCHandle.FromIntPtr(new IntPtr(address)).Target;

objHandle.Free();

还可以配合Marshal使用
Marshal

posted @ 2021-06-10 19:25  Hey,Coder!  阅读(1663)  评论(0编辑  收藏  举报