std::memcpy (3) - Linux Manuals
std::memcpy: std::memcpy
NAME
Synopsis
Defined in header <cstring>
void* memcpy( void* dest, const void* src, std::size_t count );
Copies count bytes from the object pointed to by src to the object pointed to by dest. Both objects are reinterpreted as arrays of unsigned char.
If the objects overlap, the behavior is undefined.
If either dest or src is a null pointer, the behavior is undefined, even if count is zero.
If the objects are potentially-overlapping or not TriviallyCopyable, the behavior of memcpy is not specified and may_be_undefined.
Parameters
dest - pointer to the memory location to copy to
src - pointer to the memory location to copy from
count - number of bytes to copy
Return value
dest
Notes
std::memcpy is meant to be the fastest library routine for memory-to-memory copy. It is usually more efficient than std::strcpy, which must scan the data it copies or std::memmove, which must take precautions to handle overlapping inputs.
Several C++ compilers transform suitable memory-copying loops to std::memcpy calls.
Where strict_aliasing prohibits examining the same memory as values of two different types, std::memcpy may be used to convert the values.
Example
// Run this code
Output:
See also
memmove (function)
memset (function)
wmemcpy (function)
copy
copy_if copies a range of elements to a new location
(C++11)
copy_backward (function template)
is_trivially_copyable checks if a type is trivially copyable
(C++11)