title: Do arrays get pinned before they are sent to unmanaged code?
body: <p>Let's say I'd like to call an unmanaged C++ function from C#. C++ function has the following prototype:</p>
  
  <pre><code>int doSomething(int arraySize, int* array)
  </code></pre>
  
  <p>And I call the function from C# as following:</p>
  
  <pre><code>[DllImport(MyLibrary, CallingConvention = CallingConvention.Cdecl)]
  public static int doSomething(int arraySize, int[] array)
  
  int[] myArray = new int[] { 1, 2, 3 };
  doSomething(myArray.Length, myArray);
  </code></pre>
  
  <ol>
  <li>When I do this, is <code>myArray</code> pinned? Is there any chance that garbage collector may move the array somewhere else while the unmanaged library is working on it?</li>
  <li>If it's not automatically pinned, what should I do to pin it?</li>
  <li>If it is pinned automatically, when is it unpinned again?</li>
  </ol>