3 ms·
I'm not very familiar with Rust, but I don't understand why you wouldn't just use a reference-to-HeavyThing as the function argument, so that the object isn't m
by maxton 6y ago
I'm not very familiar with Rust, but I don't understand why you wouldn't just use a reference-to-HeavyThing as the function argument, so that the object isn't moved and then dropped in the `get_size` function?
- epage 6y agoFor these contrived cases, yes, you would just pass a reference to the function but I think the point is to simplify the case down to demonstrate a point.
- burpsnard 6y agoIn the olden days, it was just out.flush(); out.close();
- Cyph0n 6y agoYou’re spot on: this is simply a bad example that you would never see in a real application.
- ehsanu1 6y agoIf you never drop it, you have a memory leak. If the caller drops it, it's still the same as the `get_size` dropping it in terms of performance impact. Generally you'd only pass ownership when that's needed for some reason. So this toy example might not be realistic but it does demonstrate the performance impact.
- heavenlyblue 6y agoSo the caller of the function still needs to free HeavyThing in the same thread.