What is the difference between memmove and memcpy?

Asked

Viewed 149 times

3

What is the difference between the function memmove() and memcpy()?

1 answer

3


The name memmove() gives a slightly wrong idea since it copies the same memcpy(), so if you really want her to move, you’ll need to delete the previous one on your own. Almost always use the second that is faster and does the job well.

The first one differs by the ability to overlay the content, ie you can play the content to a place that takes a part of itself, for example play a content forward to make room to put new data, so obviously c copy needs to occur backwards, After all you copy yourself in the normal order a content will delete something that still needs to be copied. Obviously, you need more control to make this right. A good implementation can optimize this if it is not necessary, but there will be a cost to decide this, if it were another language could only use this function, but in C this is an inappropriate cost, after all it exists to be as fast as possible in all circumstances.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.