title: Memcpy of native array to managed array in C++ CLI
body: <p>Am I doing this right?</p>
  
  <p>I get a pointer to a native array and need to copy to a managed array. Use memcpy() with a pin_ptr.</p>
  
  <pre><code>unsigned char* pArray;
  unsigned int arrayCount;
  // get pArray &amp; arrayCount (from a COM method) 
  
  ManagedClass-&gt;ByteArray = gcnew array&lt;Byte,1&gt;(arrayCount)
  pin_ptr&lt;System::Byte&gt; pinPtrArray = &amp;ManagedClass-&gt;ByteArray[0];
  memcpy_s(pinPtrArray, arrayCount, pArray, arrayCount);
  </code></pre>
  
  <p>arrayCount is the actual length of pArray, so not really worried about that aspect. Looked at the code and the array is copied from a vector. So I can set the managed array size safely.</p>