Jan 13, 2010 at 6:05pm
Hi,
is it correct(I mean "norm correct") to use "overlap" pointers as parameters of memcpy function from memory.h header?
Example:
1 2 3
|
//move 3 elements of the array one place to the right
int someArray[5];
memcpy(someArray + 1, someArray, sizeof(int) * 3);
|
Is it correct?
I could try it of course (and I did it) but memory problems are disgusting as you surely know so I want to be sure about it.
Thank you!
Last edited on Jan 13, 2010 at 6:06pm
Jan 13, 2010 at 6:11pm
No, if the source and destination buffers overlap you must use memmove instead.
Jan 13, 2010 at 6:11pm
Results are undefined due to the overlap. If the memory was in the same block but didn't overlap, then its perfectly fine.
Jan 13, 2010 at 9:05pm
It's exactly what I need to know.
Thank you so much!
Last edited on Jan 13, 2010 at 9:05pm