memcpy 和 memmove 有什么区别?

来源:互联网 发布:华南理工网络教育答案 编辑:程序博客网 时间:2024/04/28 16:06

memcpy 和 memmove 有什么区别?

memcpy和memmove都是将源地址的若干个字符拷贝到目标地址。
如果源地址和目标地址有重叠,则memcpy不能保证拷贝正确,但memmove可以保证拷贝正确。 

例如:
char src[20];
// set src
char* dst = src + 5;
此时如果要从src拷贝10个字符到dst,则么memcpy不能保证拷贝正确,但是memmove可以保证


memcpy copies count bytes from src to dest; wmemcpy copies count wide characters (two bytes). If the source and destination overlap, the behavior of memcpy is undefined. Use memmove to handle overlapping regions.


Copies count bytes (wmemmove) or characters (wmemmove) from src to dest. If some regions of the source area and the destination overlap, both functions ensure that the original source bytes in the overlapping region are copied before being overwritten.

原创粉丝点击