Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In theory, <code>memcpy</code> might have a <em>slight</em>, <em>imperceptible</em>, <em>infinitesimal</em>, performance advantage, only because it doesn't have the same requirements as <code>std::copy</code>. From the man page of <code>memcpy</code>:</p> <blockquote> <p>To avoid overflows, the size of the arrays pointed by both the destination and source parameters, shall be at least num bytes, <strong>and should not overlap</strong> (for overlapping memory blocks, memmove is a safer approach).</p> </blockquote> <p>In other words, <code>memcpy</code> can ignore the possibility of overlapping data. (Passing overlapping arrays to <code>memcpy</code> is undefined behavior.) So <code>memcpy</code> doesn't need to explicitly check for this condition, whereas <code>std::copy</code> can be used as long as the <code>OutputIterator</code> parameter is not in the source range. Note this is <em>not</em> the same as saying that the source range and destination range can't overlap.</p> <p>So since <code>std::copy</code> has somewhat different requirements, in theory it should be <em>slightly</em> (with an extreme emphasis on <em>slightly</em>) slower, since it probably will check for overlapping C-arrays, or else delegate the copying of C-arrays to <code>memmove</code>, which needs to perform the check. But in practice, you (and most profilers) probably won't even detect any difference.</p> <p>Of course, if you're not working with <a href="http://en.wikipedia.org/wiki/Plain_old_data_structure">PODs</a>, you <em>can't</em> use <code>memcpy</code> anyway.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload