Re:Rust: Dropping heavy things in another thread can make yo...
by kevincox on Saturday May 30, 2020 @04:19PM
(#23364304)
Semantically it is a bitwise copy.
In the example from the article it is probably actually a copy because the value was originally on the parent thread's stack, which will be reused after the function returns, so the value will need to be copied to the new thread's stack.
However it is important to not that it isn't a deep/recursive bitwise copy. It just needs to copy the HashMap itself (which is probably a handful of words).
So yes, it is doing a bitwise copy, but this is also very cheap. It will be much, much cheaper than spawning the thread.
Re:Rust: Dropping heavy things in another thread can make yo...
by ahupp on Saturday May 30, 2020 @04:52PM
(#23364609)
That's not exactly true. In C++ terms, the example code is moving a value:
std::map<...> foo;
someFunction(std::move(foo));
And not moving a pointer like: std::unique_ptr<std::map<...>> foo = ...;
someFunction(std::move(foo));
So it copies sizeof(std::map<...>), not a pointer.
Re:Rust: Dropping heavy things in another thread can make yo...
by pjmlp on Monday June 01, 2020 @03:23AM
(#23376073)
Not necessary, std::map::map(&&) is free to move just the internal pointers and bookkeeping data, only dumb implementations would move the memory blocks where the map data is actually stored, as per ISO C++ requirements.
Re:Rust: Dropping heavy things in another thread can make yo...
by ahupp on Monday June 01, 2020 @02:01PM
(#23381603)
The comment originally said it was the cost of a pointer copy, and I was pointing out it's not a pointer. eg., sizeof(std::map<std::string,std::string>) is 48, which is the "pointers and bookeeping" you mention.
I was thinking of the following code, where I believe the assignment to y is actually free. Though apparently this isn't called a "move".
More info: https://doc.rust-lang.org/rust-by-example/scope/move.html