00018 void *memcpy(void *dst, const void *src, size_t len)
00019 {
00020 size_t i;
00021
00022 /*
00023 * memcpy does not support overlappi
I was just going through an implementation of
memcpy, to understand how it differs from using a loop. But I couldn't see any difference between using a loop rather than memcpy, asmemcpyuses loop again internally to copy.
Loop (control statements) is one of the basic elements adjacent to if (decision statements) and few other such things. So the question here is not about what is the difference between normal looping and using memcpy.
memcpy just aids your task by providing you with a ready to use API call, instead of having you to write 20 lines of code for a petty thing. If you wish so, you can choose to write your own code to provide you with the same functionality.
Second point as already pointed out earlier is that, the optimization it provides between long data type and other types. Because in long it is copying a block of data at once what we call a word instead of copying byte by byte which would take longer time. In case of long, the same operation that would require 8 iterations to complete, memcpy does it in a single iteration by copying the word at once.