VS的memcpy用C分配 [英] memcpy vs assignment in C

查看:438
本文介绍了VS的memcpy用C分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我应该期待memcpys什么情况下对现代INTEL / AMD硬件跑赢分配?我使用的是32位的Intel平台上GCC 4.2.x版(但很感兴趣,64位为好)。

Under what circumstances should I expect memcpys to outperform assignments on modern INTEL/AMD hardware? I am using GCC 4.2.x on a 32 bit Intel platform (but am interested in 64 bit as well).

推荐答案

您永远不应该期望他们跑赢大盘分配。原因是,当它认为它会更快编译器将使用的memcpy呢(如果使用优化标志)。如果没有,如果结构合理小,它适合寄存器,直接操纵寄存器可以使用这将不需要任何内存访问的。

You should never expect them outperform assignments. The reason is, the compiler will use memcpy anyway when it thinks it would be faster (if you use optimize flags). If not and if the structure is reasonable small that it fits into registers, direct register manipulation could be used which wouldn't require any memory access at all.

GCC具有特殊的块移动模式的内部找出当直接更改寄存器/存储器单元,或当使用memcpy函数。请注意,当分配结构,编译器知道在编译的时候,此举有多大将是,所以它可以展开小型副本(做一个移动n次行而不是循环)的实例。注 -mno-memcpy的

GCC has special block-move patterns internally that figure out when to directly change registers / memory cells, or when to use the memcpy function. Note when assigning the struct, the compiler knows at compile time how big the move is going to be, so it can unroll small copies (do a move n-times in row instead of looping) for instance. Note -mno-memcpy:

-mmemcpy
-mno-memcpy
    Force (do not force) the use of "memcpy()" for non-trivial block moves.  
    The default is -mno-memcpy, which allows GCC to inline most constant-sized copies.

谁更好知道它时使用的memcpy比编译器本身?

Who knows it better when to use memcpy than the compiler itself?

这篇关于VS的memcpy用C分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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