This is more a question out of curiosity than anything important, but I was just wondering about the following snippet in the memmove
documentation:
Copying takes place as if an intermediate buffer were used
(emphasis mine). The formulation suggests to me that whether an intermediate buffer is used, is specific to the compiler implementation.
If you would ask me to write memmove
, I would probably automatically do the following:
- allocate
n
bytes on the heap memcpy
the source to the tempmemcpy
the temp to the destination- free the buffer
I was hoping anyone could ...
- ... confirm whether the formulation is only because it's easier for users to visualize what is going on, without fixing that specific implementations actually have to use an intermediate buffer;
- ... shed some light on the actual implementation in some common C++ compilers (like
gcc
or Visual C++) - for example, does it use a buffer and does it check for overlap so it canmemcpy
directly; - ... maybe point out the blatantly obvious error / inefficiency in my simple algorithm above.