memmove、wmemmovememmove, wmemmove

将一个缓冲区移到另一个缓冲区。Moves one buffer to another. 提供这些函数的更多安全版本;请参阅 memmove_s、wmemmove_sMore secure versions of these functions are available; see memmove_s, wmemmove_s.


void *memmove(
   void *dest,
   const void *src,
   size_t count
wchar_t *wmemmove(
   wchar_t *dest,
   const wchar_t *src,
   size_t count


目标对象。Destination object.

源对象。Source object.

字节数 (memmove) 或多个字符 (wmemmove) 复制。Number of bytes (memmove) or characters (wmemmove) to copy.

返回值Return Value

destThe value of dest.


副本计数字节 (memmove) 或多个字符 (wmemmove) 从srcdestCopies count bytes (memmove) 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.

安全说明 确保目标缓冲区的大小等于或大于源缓冲区的大小。Security Note Make sure that the destination buffer is the same size or larger than the source buffer. 有关详细信息,请参阅 避免缓冲区溢出For more information, see Avoiding Buffer Overruns.

Memmovewmemmove函数将仅会弃用常量 _CRT_SECURE_DEPRECATE_MEMORY顺序中的包含语句之前定义要为不推荐使用,例如以下示例所示的函数:The memmove and wmemmove functions will only be deprecated if the constant _CRT_SECURE_DEPRECATE_MEMORY is defined prior to the inclusion statement in order for the functions to be deprecated, such as in the example below:

#include <string.h>


#include <wchar.h>


例程所返回的值Routine 必需的标头Required header
memmovememmove <string.h><string.h>
wmemmovewmemmove <wchar.h><wchar.h>

有关其他兼容性信息,请参阅 兼容性For additional compatibility information, see Compatibility.


// crt_memcpy.c
// Illustrate overlapping copy: memmove
// always handles it correctly; memcpy may handle
// it correctly.

#include <memory.h>
#include <string.h>
#include <stdio.h>

char str1[7] = "aabbcc";

int main( void )
   printf( "The string: %s\n", str1 );
   memcpy( str1 + 2, str1, 4 );
   printf( "New string: %s\n", str1 );

   strcpy_s( str1, sizeof(str1), "aabbcc" );   // reset string

   printf( "The string: %s\n", str1 );
   memmove( str1 + 2, str1, 4 );
   printf( "New string: %s\n", str1 );
The string: aabbcc
New string: aaaabb
The string: aabbcc
New string: aaaabb

请参阅See also

缓冲区操作Buffer Manipulation
memcpy、wmemcpymemcpy, wmemcpy
strcpy、wcscpy、_mbscpystrcpy, wcscpy, _mbscpy
strncpy、_strncpy_l、wcsncpy、_wcsncpy_l、_mbsncpy、_mbsncpy_lstrncpy, _strncpy_l, wcsncpy, _wcsncpy_l, _mbsncpy, _mbsncpy_l