gpt4 book ai didi

swift - Swift 中的哪些值类型支持写时复制?

转载 作者:搜寻专家 更新时间:2023-10-30 22:12:27 25 4
gpt4 key购买 nike

我阅读了有关 Swift 中 Array 的写时复制实现 here .

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.

我想知道您是否知道哪种结构支持写时复制。

最佳答案

写入时复制支持 String 和所有集合类型 - ArrayDictionarySet

除此之外,编译器可以自由优化任何结构访问并有效地为您提供写时复制语义,但不能保证。

关于swift - Swift 中的哪些值类型支持写时复制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45253202/

25 4 0