问题描述
我抄袭 PSRC
N个字节为 pDest
。这可以在一个单一的环进行:
I am copying N bytes from pSrc
to pDest
. This can be done in a single loop:
for (int i = 0; i < N; i++)
*pDest++ = *pSrc++
这是为什么比的memcpy
慢或 memmove与
?他们使用什么招数来加快步伐?
Why is this slower than memcpy
or memmove
? What tricks do they use to speed it up?
推荐答案
由于memcpy的使用字指针,而不是字节的指针,也是实现的memcpy往往写有的这使得有可能在一个时间洗牌128位
Because memcpy uses word pointers instead of byte pointers, also the memcpy implementations are often written with SIMD instructions which makes it possible to shuffle 128 bits at a time.
SIMD指令是组件可在多达16个字节长的向量每个元素执行相同的操作指令。这包括加载和存储指令。
SIMD instructions are assembly instructions that can perform the same operation on each element in a vector up to 16 bytes long. That includes load and store instructions.
这篇关于为什么的memcpy()和memmove与()比指针加快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!