..
memcpy vs.memmove
这两个函数都包含在头文件 #include <string.h>
中1。
memcpy 的函数原型
void *memcpy(void *restrict dest, const void *restrict src, size_t n);
描述
The memcpy() function copies n bytes from memory area src to memory area dest. The memory areas must not overlap. Use memmove(3) if the memory areas do overlap.
返回值
The memcpy() function returns a pointer to dest.
属性
┌──────────────────────────────────────┬───────────────┬─────────┐
│Interface │ Attribute │ Value │
├──────────────────────────────────────┼───────────────┼─────────┤
│memcpy() │ Thread safety │ MT-Safe │
└──────────────────────────────────────┴───────────────┴─────────┘
memmove 的函数原型
void *memmove(void *dest, const void *src, size_t n);
描述
The memmove() function copies n bytes from memory area src to memory area dest. The memory areas may overlap: copying takes place as though the bytes in src are first copied into a temporary array that does not overlap src or dest, and the bytes are then copied from the temporary array to dest.
返回值
The memmove() function returns a pointer to dest.
属性
┌──────────────────────────────────────┬───────────────┬─────────┐
│Interface │ Attribute │ Value │
├──────────────────────────────────────┼───────────────┼─────────┤
│memmove() │ Thread safety │ MT-Safe │
└──────────────────────────────────────┴───────────────┴─────────┘
区别
memmove 可以拷贝有 overlap
的情况。