I have a managed class which contains unmanaged class pointer:
class Managed { public IntPtr ptr; };
c++ function which takes a pointer as parameter:
void foo(void *ptr);
should i pin this Managed object before calling the unmanaged function?
calling code:
Managed obj = new Managed;
foo(obj.ptr);
I don’t see why you’d need to pin it – even if the GC moves
objitself, the value ofobj.ptrshouldn’t be affected – andobj.ptris passed to your C++ code by value, so it’s not like the C++ code can try to change the contents ofobj.