为什么memcpy()和memmove()比指针增量快? [英] Why are memcpy() and memmove() faster than pointer increments?

查看:125
本文介绍了为什么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++

为什么它比memcpymemmove慢?他们使用什么技巧来加快速度?

Why is this slower than memcpy or memmove? What tricks do they use to speed it up?

推荐答案

由于memcpy使用字指针而不是字节指针,因此memcpy实现通常也用

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()比指针增量快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆