memcpy, wmemcpy
The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.
The latest version of this topic can be found at memcpy, wmemcpy.
Copies bytes between buffers. More secure versions of these functions are available; see memcpy_s, wmemcpy_s.
void *memcpy( void *dest, const void *src, size_t count ); wchar_t *wmemcpy( wchar_t *dest, const wchar_t *src, size_t count );
Parameters
dest
New buffer.
src
Buffer to copy from.
count
Number of characters to copy.
The value of dest.
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.
Make sure that the destination buffer is the same size or larger than the source buffer. For more information, see Avoiding Buffer Overruns. |
Because so many buffer overruns, and thus potential security exploits, have been traced to improper usage of Because |
The memcpy and wmemcpy 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:
#define _CRT_SECURE_DEPRECATE_MEMORY #include <memory.h>
or
#define _CRT_SECURE_DEPRECATE_MEMORY #include <wchar.h>
| Routine | Required header |
|---|---|
memcpy | <memory.h> or <string.h> |
wmemcpy | <wchar.h> |
For additional compatibility information, see Compatibility in the Introduction.
See memmove for a sample of how to use memcpy.
Buffer Manipulation
_memccpy
memchr, wmemchr
memcmp, wmemcmp
memmove, wmemmove
memset, wmemset
strcpy_s, wcscpy_s, _mbscpy_s
strncpy_s, _strncpy_s_l, wcsncpy_s, _wcsncpy_s_l, _mbsncpy_s, _mbsncpy_s_l