Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

memmove doesn't move

Tags:

c++

c

memory

libc

memmove doesn't really move memory isn't that right? It just copies memory from one region to other and allows those two regions to overlap. I'm asking this question because I just want to know why is this fnc called in very misleading manner.
For I understand that when something is moved from one place to the other, the "thingy" is after this operation in the other place and not in the first. And with memmove it doesn't work that way. Am I right?

like image 875
There is nothing we can do Avatar asked Nov 27 '22 10:11

There is nothing we can do


1 Answers

You are right, it copies it. However, there is a difference between memmove and memcpy, because memmove can treat correctly the case when the buffers overlap, so it is recomended in these cases.

However, because of additional checks that memmove performs, when the buffers are small and surely does not overlap, memcpy is better.

like image 64
ruslik Avatar answered Dec 09 '22 11:12

ruslik