Viewing posts for the category Programming

memcpy() vs memmove()

Way back when I first started C programming, I wanted to find an easy way to copy one block of memory to another block of memory. The first thing I discovered when digging through documentation was the memcpy() function, which basically does exactly what its name indicates -- copy memory from one location to another. The documentation also talked about a related function called memmove(), which I thought must "move memory from one location to another," so I didn't pay it much attention as I wanted to copy memory, not move it. Yeah, I knew that memcpy() wouldn't behave if the memory regions you were copying overlapped, but I was like "okay, I just won't be stupid and copy between overlapping regions," and, fortunately, the way I used it over the years happened to never result in a situation were those regions would overlap (I think... I've written a lot of code, but don't recall ever debugging an issue due to a bizarre memcpy()-related corruption).