The technical difference has been well documented by previous answers. Practical differences should also be noted:
Memcpy will require approximately twice as much memory to complete the same task, but memmove can take significantly longer than memcpy.
Example:
Say you have a list of 100 items in memory that accept 100 MB of memory. You want to reset 1st element so that you have 99.
To get a new list of 99 Memcpy items, you will need the original 100 MB and an additional 99 MB. Approximately 199 MB to complete the operation, but should be very fast.
Memmove, in the worst case scenario, you will need the original 100 MB and will move each memory item 1 item at a time. It only requires 100 MB, but will be significantly slower than Memcpy.
Of course, creating a new pointer pointing to the second element in your list will have the same effect of โdroppingโ the first element from your list, but the example shows the differences in memcpy and memmove.
- CHANGE TO HELP COMPLETE MY CARPIAN RESPONSE -
Yes, the implementation of memcpy () and memmove () probably doesn't differ in memory usage (I really don't know), but the way you use them will greatly affect the memory usage of your program. This is what I meant by the practical differences memcpy () and memmove ().
int SIZE = 100; Item *ptr_item = (Item *) malloc(size_of(Item) * SIZE); Item *ptr_src_item = ptr_item + 1; Item *ptr_dst_item = ptr_item; memmove(ptr_dst_item, ptr_src_item, SIZE - 1);
Creates a list of items with no first item. This essentially does not require more memory for your program than what is required to allocate the original ptr_item memory block. You cannot do this with memcpy () ... if you did, your program would have to allocate approximately twice as much memory.
int SIZE = 100; Item *ptr_src_item = (Item *) malloc(size_of(Item) * SIZE); Item *ptr_dst_item = (Item *) malloc(size_of(Item) * (SIZE - 1)); memcpy(ptr_dst_item, ptr_src_item, SIZE - 1);
In this second block of code, the program will require twice as much memory as the first block. However, this second block should run much faster than the first block, especially as the size increases.
The way I tried to explain the practical differences in the two ... but maybe I'm wrong about that too?