什么是的memmove和memcpy区别? [英] What is the difference between memmove and memcpy?

查看:492
本文介绍了什么是的memmove和memcpy区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是 memmove与的memcpy 之间的区别?哪一个你平时使用又如何?

What is the difference between memmove and memcpy? Which one do you usually use and how?

推荐答案

通过的memcpy ,目标不能在所有重叠的来源。随着 memmove与就可以了。这意味着 memmove与可能比的memcpy 很稍微慢一些,因为它不能做出同样的假设。

With memcpy, the destination cannot overlap the source at all. With memmove it can. This means that memmove might be very slightly slower than memcpy, as it cannot make the same assumptions.

例如,的memcpy 总是会复制地址从低到高。如果目标源后重叠,这意味着之前复制了一些地址将被覆盖。 memmove与将检测这一点,并复制在另一个方向 - 从高至低 - 在这种情况下。然而,检查这个和切换到另一(可能效率较低)算法需要时间。

For example, memcpy might always copy addresses from low to high. If the destination overlaps after the source, this means some addresses will be overwritten before copied. memmove would detect this and copy in the other direction - from high to low - in this case. However, checking this and switching to another (possibly less efficient) algorithm takes time.

这篇关于什么是的memmove和memcpy区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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