4 ms·
> That's exactly what happens: a Rust "move" is under the covers a memcpy(). Is it really? I had always assumed that the compiler would almost always optimize
by Asraelite 6y ago
> That's exactly what happens: a Rust "move" is under the covers a memcpy().
Is it really? I had always assumed that the compiler would almost always optimize a move down to nothing, simply reusing the address. If access to the address is still exclusive, what would be the benefit of moving it in memory?
memcpy sounds like what would happen in the case of a copy or clone, not a move.
- cesarb 6y agoYes, the optimizer (LLVM) can often optimize memcpy(), and this is not exclusive to Rust: the same optimizations happen with C and C++ (a well-known trick to avoid some undefined behaviors in C is to do a memcpy(), which the optimizer will then elide). It doesn't change that, before the optimization passes, it's doing the equivalent of a memcpy(). > memcpy sounds like what would happen in the case of a copy or clone, not a move. In Rust, copy and move are nearly identical; the only difference is that, after a move, the compiler doesn't let you access the old value. Clone is different, since it can be overridden to do anything the programmer desires, but by default, it's identical to copy.