So, you have like 5 elements in your vector. You want to shift down. You would start from the beginning moving the first element. Then the 2nd etc etc. You would do the moving with memmove().
Now, I don't know exactly what you mean with shift down (like what will happen to the 1st element and the last?) but memove() seems to be ok.
It probably WON'T move the entire block, meaning the entire remaining vector. It will just copy the element where you specify. If there is used-up memory, that memory will be overwritten.
Like you have a vector of char.
'a' 'b' 'c' 'd'
You move shift down. The first elements lets say gets lost and the last becomes '0'. You will have:
memmove(1,2) --> so 'b' 'b' 'c' 'd'
memmove(2,3) --> so 'b' 'c' 'c' 'd'
memmove(3,4) --> so 'b' 'c' 'd' 'd'
4 = '0' --> so 'b' 'c' 'd' '0'
That is what I understand with memmove() you will use sizeof(type_of_element) for the shifting offset. Here sizeof(char).
memcpy() won't work because it overlaps some memory used (I don't know what will happen)
A final note. I haven't ever used them, so I am just guessing here. Someone more experience should confirm (or slap me)
EDIT: Let me answer though directly the question.
Lets say you have:
Code:
char* str = "dude";
memmove(str+1, str,3);
printf("%s",str);
you will probably have "ddud". What happens is that ['d']['u'['d'] is copied to a temporary buffer. Then that is copied where specified.
Now if you used memcpy() instead of memmove() then NO temporary buffer is used. So this might happend:
1) ['d']['u']['d']['e'] original
2) ['d']['d']['d']['e'] after first copy (copies 1st element to the 2nd element)
3) ['d']['d']['d']['e'] after second copy (copies 2nd element to the 3rd element)
4) ['d']['d']['d']['d'] after third copy (copies 3nd element to the 4rd element)
So you will have "dddd". Why? Because you write/read in the same place, so the reading data get altered by the writing data.