std::move
does not move the object. It moves the meaning. (Think of the MOV R1, R2
instruction in some machine language: it does not move the registers, just the contents! Or the memmove
library function. This is a feeling of "moving", and not what happens when copying or compressing garbage collectors that force an object be at a different address, while maintaining its accurate identification, which includes searching for every link to a moved object everywhere on the machine and updating it).
move semantics is a new function in C ++ that allows you to copy an object in such a way that the old value does not need to be saved. This is useful in cases where the old object is no longer needed, because it can be faster.
For example, moving a vector from one std::vector<X>
to another can cause the original object to be a zero-length vector, and all data will be moved without any memory allocation or copying. Since the idea is that the old vector is not used, it does not matter that it has been flattened to zero length.
There is no reason why this will not work between locations located in different repositories (for example, free storage ("heap") for automatic storage ("stack"), given that building a copy between such operands always worked fine in C ++ .
source share