# 05.Copy-on-write

## 什么是 COW

Copy on write

* COW是一种常见的计算机技术，有助于在复制结构时提高效率
  * 例如一个数组有100个元素，赋值到另一个数组，赋值所有元素，即最终两个数组内容相同
* 当使用COW的话
  * 当将两个变量指向同一数组时，他们指向相同的底层数据。两个变量指向相同的数据可能看起来矛盾，当修改第二个变量的时候，Swift才会去复制一个副本，第一个不会改变。
* 通过延迟复制操作，直到实际使用到的时候 才去复制，以此确保没有浪费的工作。

> COW是特别添加到Swift数组和字典的功能，自定义的数据类型不会自动实现。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ryukiedev.gitbook.io/wiki/swift/cow.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
