Why are memcpy() and memmove() faster than pointer increments?(为什么 memcpy() 和 memmove() 比指针增量快?)
问题描述
我正在将 N 个字节从 pSrc 复制到 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 的实现也经常用 SIMD 指令,可以一次对 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() 比指针增量快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么 memcpy() 和 memmove() 比指针增量快?
基础教程推荐
- 初始化列表*参数*评估顺序 2021-01-01
- CString 到 char* 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
