Re:Impressions of Rust as a Swift Developer: Memory Management
by monocularvision on Wednesday March 11, 2020 @10:35AM
(#22546168)
The author is wrong in their description. Some value types in Swift (like the standard library collection types like Array<T>) are value types with copy-on-write behavior. Until modified, copies of the Array are not made.
That copy-on-write functionality must be purposely implemented in the type and is not something provided automatically in Swift.
That isn't copy-on-write, that's just copy.
Does "copy-on-write" mean that Swift behaves as if it is doing this, but actually defers copies where it can, passing references to the original until a function needs to modify its 'copy'?
Rust lets you do this explicitly via the Cow smart pointer:
https://doc.rust-lang.org/std/borrow/enum.Cow.html
But it's not transparent, and it's not used a lot in practice.