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

dest 的值。The value of dest.


副本count字节 (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.

仅当为了弃用函数而将常量 memmove 先于包含语句定义时,才会弃用 wmemmove_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
memmove <string.h><string.h>
wmemmove <wchar.h><wchar.h>

有关其他兼容性信息,请参见“简介”中的 兼容性For additional compatibility information, see Compatibility in the Introduction.


// 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
_memccpy _memccpy
memcpy、wmemcpy memcpy, wmemcpy
strcpy、wcscpy、_mbscpy strcpy, wcscpy, _mbscpy
strncpy、_strncpy_l、wcsncpy、_wcsncpy_l、_mbsncpy、_mbsncpy_lstrncpy, _strncpy_l, wcsncpy, _wcsncpy_l, _mbsncpy, _mbsncpy_l