Copying and Pinning When marshaling data, the interop marshaler
can copy or pin the data being marshaled. Copying the data
places a copy of data from one memory location in another memory
location. The following illustration shows the differences
between copying a value type and copying a type passed by
reference from managed to unmanaged memory. Method arguments
passed by value are marshaled to unmanaged code as values on the
stack. The copying process is direct. Arguments passed by
reference are passed as pointers on the stack. Reference types
are also passed by value and by reference. As the following
illustration shows, reference types passed by value are either
copied or pinned. Pinning temporarily locks the data in its
current memory location, thus keeping it from being relocated by
the common language runtime's garbage collector. The marshaler
pins data to reduce the overhead of copying and enhance
performance. The type of the data determines whether it is
copied or pinned during the marshaling process