What is the difference between memmove
and memcpy
? Which one do you usually use and how?
simply from the ISO/IEC:9899 standard it is well described.
7.21.2.1 The memcpy function
[...]
2 The memcpy function copies n characters from the object pointed to by s2 into the object pointed to by s1. If copying takes place between objects that overlap, the behavior is undefined.
And
7.21.2.2 The memmove function
[...]
2 The memmove function copies n characters from the object pointed to by s2 into the object pointed to by s1. Copying takes place as if the n characters from the object pointed to by s2 are first copied into a temporary array of n characters that does not overlap the objects pointed to by s1 and s2, and then the n characters from the temporary array are copied into the object pointed to by s1.
Which one I usually use acording to the question, depends on what functionallity I need.
In plain text memcpy()
doesn't allow s1
and s2
to overlap, while memmove()
does.