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() 比指针增量快?
基础教程推荐
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 常量变量在标题中不起作用 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何通过C程序打开命令提示符Cmd 2022-12-09
