Created
September 9, 2019 06:13
-
-
Save M-Yankov/71fe5267ab83182e502b56c55dd7f385 to your computer and use it in GitHub Desktop.
Returns the address of the memory refferensed by object.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public unsafe void Get(MyModel a) | |
{ | |
System.Runtime.InteropServices.GCHandle handle = System.Runtime.InteropServices.GCHandle.Alloc(a, System.Runtime.InteropServices.GCHandleType.Weak); | |
try | |
{ | |
IntPtr pointer = System.Runtime.InteropServices.GCHandle.ToIntPtr(handle); | |
string test = "0x" + pointer.ToString("X"); | |
} | |
finally | |
{ | |
handle.Free(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment