Most efficient way of copying a raw byte array into an empty byte vector
<p>I have a scenario in which I need to copy the contents of a raw dynamically allocated <code>uint8_t</code> array into a vector (which is guaranteed to be <strong>empty</strong> whenever this scenario happens).</p>

<pre><code>vector&lt;uint8_t&gt; myVector;
const uint8_t* myRawArray;
</code></pre>

<p>It is really important to me that the copy operation is as efficient as possible and portable (various compiler versions might be used).</p>

<p>One approach I thought of using is this:</p>

<pre><code>myVector.reserve(byteCount);
myVector.insert(myVector.begin(), myRawArray, myRawArray + byteCount);
</code></pre>

<p>Any ideas on how the speed of that compares to this one:</p>

<pre><code>myVector.resize(byteCount);
memcpy(myVector.data(), myRawArray, byteCount);
</code></pre>

<p>I guess <code>memcpy</code> should be fast but then I am forced to use <code>resize</code> which needs to zero-out the memory, so I guess it will slow it down a bit..</p>

<p>Also, any other suggestions?</p>