std :: copy vs memcpy的效率 [英] Efficiency of std::copy vs memcpy
问题描述
使用 memcpy
和 std :: copy
之间的效率损失有多严重?
How severe is the efficiency loss between using memcpy
and std::copy
?
我有一种情况,我的系统上的向量实现似乎没有使用连续的内存,这使得我必须std ::复制其内容后,而不是 memcpy(dest,& vec [0],size);
。
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).
如果你的实现没有连续的存储(C ++ 03标准需要它), memmove
可能比 std :: copy
,但可能不会太多。我会开始担心只有当你有测量表明它确实是一个问题。
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.
这篇关于std :: copy vs memcpy的效率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!