Skip to content

Latest commit

 

History

History
117 lines (88 loc) · 3.01 KB

memmove-wmemmove.md

File metadata and controls

117 lines (88 loc) · 3.01 KB
description title ms.date api_name api_location api_type topic_type f1_keywords helpviewer_keywords
Learn more about: memmove, wmemmove
memmove, wmemmove
1/14/2021
memmove
wmemmove
msvcrt.dll
msvcr80.dll
msvcr90.dll
msvcr100.dll
msvcr100_clr0400.dll
msvcr110.dll
msvcr110_clr0400.dll
msvcr120.dll
msvcr120_clr0400.dll
ntdll.dll
ucrtbase.dll
ntoskrnl.exe
DLLExport
apiref
memmove
wmemmove
wmemmove function
memmove function

memmove, wmemmove

Moves one buffer to another. More secure versions of these functions are available; see memmove_s, wmemmove_s.

Syntax

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

Parameters

dest
Destination object.

src
Source object.

count
Number of bytes (memmove) or characters (wmemmove) to copy.

Return value

The value of dest.

Remarks

Copies count bytes (memmove) or characters (wmemmove) from src to dest. If some portions of the source and the destination regions 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.

The memmove and wmemmove functions will only be deprecated if the constant _CRT_SECURE_DEPRECATE_MEMORY is defined before the inclusion statement in order for the functions to be deprecated, such as in the example below:

#define _CRT_SECURE_DEPRECATE_MEMORY
#include <string.h>

or

#define _CRT_SECURE_DEPRECATE_MEMORY
#include <wchar.h>

Requirements

Routine Required header
memmove <string.h>
wmemmove <wchar.h>

For more compatibility information, see Compatibility.

Example

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