How severe is the efficiency loss between using memcpy
and std::copy
?
I have a situation where the vector implementation on my system doesn't appear to use contiguous memory, which is making me have to std::copy its contents later on rather than doing memcpy(dest, &vec[0], size);
. I'm not sure how badly this is likely to impact efficiency.
A reasonably decent implementation will have std::copy
compile to a call memmove
in the situations where this is possible (i.e. the element type is a POD).
If your implementation doesn't have contiguous storage (the C++03 standard requires it), memmove
might be faster than std::copy
, but probably not too much. I would start worrying only when you have measurements to show it is indeed an issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With