title: Copy unmanaged data into managed array
body: <p>I need to copy native (i.e. unmanaged) data (byte*) to managed byte array with C++/CLI (array).</p>
  
  <p>I tried Marshal::Copy (data is pointed to by const void* data and is dataSize bytes)</p>
  
  <pre><code>array&lt;byte&gt;^ _Data=gcnew array&lt;byte&gt;(dataSize);
  System::Runtime::InteropServices::Marshal::Copy((byte*)data, _Data, 0, dataSize);
  </code></pre>
  
  <p>This gives error C2665: none of the 16 overloads can convert all parameters. Then I tried</p>
  
  <pre><code>System::Runtime::InteropServices::Marshal::Copy(new IntPtr(data), _Data, 0, dataSize);
  </code></pre>
  
  <p>which produces error C2664: parameter 1 cannot be converted from "const void*" to "__w64 int".</p>
  
  <p>So how can it be done and is Marshal::Copy indeed the "best" (simplest/fastest) way to do so?</p>