I read about copy-on-write implementation for Array in Swift here.
我在这里阅读了Swift中关于Array的copy-on-write实现。
Arrays, like all variable-size collections in the standard library, use copy-on-write optimization. Multiple copies of an array share the same storage until you modify one of the copies. When that happens, the array being modified replaces its storage with a uniquely owned copy of itself, which is then modified in place. Optimizations are sometimes applied that can reduce the amount of copying.
与标准库中的所有可变大小集合一样,数组使用copy-on-write优化。在您修改其中一个副本之前,阵列的多个副本共享相同的存储。当发生这种情况时,被修改的数组将使用其自身的唯一拥有副本替换其存储,然后对其进行修改。有时会应用优化,可以减少复制量。
I was wondering if you have any information about which structure supports copy-on-write.
我想知道你是否有任何关于哪种结构支持写时复制的信息。
1 个解决方案
#1
5
Copy-on write is supported for String
and all collection types - Array
, Dictionary
and Set
.
String和所有集合类型支持Copy-on write - Array,Dictionary和Set。
Besides that, compiler is free to optimize any struct access and effectively give you copy-on-write semantics, but it is not guaranteed.
除此之外,编译器可以*地优化任何结构访问,并有效地为您提供写时复制语义,但不保证。
#1
5
Copy-on write is supported for String
and all collection types - Array
, Dictionary
and Set
.
String和所有集合类型支持Copy-on write - Array,Dictionary和Set。
Besides that, compiler is free to optimize any struct access and effectively give you copy-on-write semantics, but it is not guaranteed.
除此之外,编译器可以*地优化任何结构访问,并有效地为您提供写时复制语义,但不保证。