How does the memory overlap occur and how is it controlled?

user379888 picture user379888 · Sep 3, 2010 · Viewed 8.1k times · Source

While reading about memmove I read that it can handle MEMORY OVERLAPSbut I am unable to get how a memmory overlap can occur between two strings and how can this function still copy the block of memory correctly.

Answer

AnT picture AnT · Sep 3, 2010

"Memory overlap" does not occur by itself. It is you who can supply the memmove function with memory regions that overlap. Take two pointers into the same array and you can easily end up with overlapping memory regions.

Of course, you can also easily create overlapping objects through unions.

It is not clear what you mean by the second part of the question ("how can this function still copy the block of memory correctly"). Where do you see the problem here?