What types of values ​​in Swift support copy-on-write?

I read about the implementation of copy-on-write for Array in Swift here .

Arrays, like all variable-size collections in the standard library, use copy-to-write optimization. Multiple copies of the array use the same storage until you change one of the copies. When this happens, the modifiable array replaces its storage with a unique copy of itself, which is then modified in place. Sometimes optimizations are applied that can reduce the amount of copy.

I was wondering if you have any information on which structure supports copy-on-write.

+5
source share
1 answer

Copying is supported for String and all types of collections - Array , Dictionary and Set .

In addition, the compiler can optimize any access to the structure and effectively provide you with copy-on-write semantics, but this is not guaranteed.

+5
source

Source: https://habr.com/ru/post/1270095/


All Articles