tags:

views:

40

answers:

1

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);
+1  A: 

I don't see why you'd need to pin it - even if the GC moves obj itself, the value of obj.ptr shouldn't be affected - and obj.ptr is passed to your C++ code by value, so it's not like the C++ code can try to change the contents of obj.

Jon Skeet
thanks, this is what i am assuming.
Benny