tags:

views:

257

answers:

1

Hello, I'm writing a wrapper app that uses some unmanaged functions and I'm using a lot of pin_ptr.

My question is, most of the time I use pin_ptr inside a method call, and the pin_ptr variable is declared also inside the method call. When the code goes our of the method, can I have any problem because it's no longer pinned? Should I move the declaration to a class scope?

thanks!

+2  A: 

The only time you need to pin an object on the managed heap is when an unmanaged function or unmanaged code directly accesses the object in memory (such as through a pointer). If when your method exits, nothing is currently accessing the object's memory, it can be unpinned (as long as you pin it again before directly accessing it the next time).

Nick Meyer