Performance notes — copy-on-write
Understand Swift String performance: copy-on-write (COW), substring sharing, and how to manage memory efficiently.
Intro
Goal: Learn how Strings use copy-on-write (COW) to balance performance and safety. Substrings also share memory until needed.
Shared storage
Assigning a String does not immediately copy characters. Both share the same storage.
var a = "Hello World"
var b = a // no real copy yet
print(a, b)All lessons in this course
- Strings & Unicode — graphemes, indices, substrings, APIs
- Common APIs — prefix/suffix/contains, split/join
- Performance notes — copy-on-write