I have two doubts about the use of memmove():
- When is it preferable to use this function instead of using another function (i.e. a created own function)? I’m not sure I have understood properly.
- The signature of the function is void *memmove(void *dest, const void *src, size_t n). If I have a simple array arr[N], how can I put it into the called function? arr[N] or &arr[N]? The difference is if the array is declared with an initial size or like a pointer? I have this doubt because I saw many examples where is used both.
I hope I explained my doubts in a good way.
edit: I have to delete an element from the array, and then I want to shift the following elements of the deleted one on the left.
memmove
may be faster but it probably will never be slower than your own function for copying data around (it's usually coded in carefully crafted assembly to move stuff around in the most efficient way possible on the current architecture);arr
will suffice (and, as the length parameter, you should dosizeof(*arr)*N
where N is the number of elements to copy).By the way, if source and destination and the copy are nonoverlapping
memcpy
may be faster.(
sizeof(*arr)
means "get the size of an element of the array")