The cow(copy on write) doesn't work for custom structures and basic data types(except strings), but I'm wondering why. Can I know the relevant reference?
I learned that when copying a value called cow, it is a memory-saving technique by sharing the original until one of the values modifies it. However, as far as I know, the type that cow works is limited to the collection type only. Is this because cow works optimally when dealing with large amounts of data? Also, why doesn't cow work when copying custom structures or basic data types?
AFAIK, copy-on-write is used to optimize performance, thus, it should affect the data structure which could potentially cost a lot of memory. To match with this proposal, there are array, string, dictionaries, etc.
Btw, you can absolutely implement copy-on-write by yourself with
isKnownUniquelyReferenced. For more information, check this.