O'Reilly logo

Swift Programming: The Big Nerd Ranch Guide by John Gallagher, Matthew Mathias

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

For the More Curious: Copy on Write

At this point, you may be wondering whether the copy behavior of Swift’s value types has any performance implications. For example, if you get a new copy of an Array every time you pass it into a function or assign it to a new constant or variable, won’t you have a wasteful number of copies floating about? In reality, it depends on your data and how you are using it. In practice, the value types in Swift’s standard library implement something called copy on write.

Copy on write, or COW, refers to the implicit sharing of value types’ underlying storage. This optimization allows instances of a value type to share their underlying storage, meaning that each instance does not have its own copy of the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required