开发者

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

开发者 https://www.devze.com 2023-01-14 03:40 出处:网络
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 th

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.


"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?


 memmove(p+1, p, 42);

Which requires moving the bytes starting at the end. Memcpy() makes a mess of it.

0

精彩评论

暂无评论...
验证码 换一张
取 消