Skip to content

Instantly share code, notes, and snippets.

@M-Yankov
Created September 9, 2019 06:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save M-Yankov/71fe5267ab83182e502b56c55dd7f385 to your computer and use it in GitHub Desktop.
Save M-Yankov/71fe5267ab83182e502b56c55dd7f385 to your computer and use it in GitHub Desktop.
Returns the address of the memory refferensed by object.
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