Re:A half-hour to learn Rust
by gpm on Saturday January 02, 2021 @12:17PM
(#25614329)
Most languages just clone all day long, it's not that bad, rust clones (like most languages) are just to the first reference counted pointer after all.
[ Parent
| on HN ]
Well, yes and no.
Eg cloning a string leads to an extra allocation and a memcopy.
If you want to get a similar performance profile to GC languages, you have to stick your types behind a `Rc<T>>/Arc<T>` or `Rc<RefCell<T>> / Arc<Mutex<T>>` if you need mutability.
But modern allocators hold up pretty well to a GC, which amortizes the allocations. The extra memcopying can be less detrimental than one might think.
Re:A half-hour to learn Rust
by throwaway894345 on Saturday January 02, 2021 @04:11PM
(#25616574)
“Yes and no” is too generous; most languages clone only very infrequently (basically only for primitives where there is no distinction between a deep and shallow copy). For complex types (objects and maps and lists) they pass references (sometimes “fat” references, but nevertheless, not a clone).