Chapter 13. Lazy Optimization, Part 1: A Plain Old String

Difficulty: 2

Copy-on-write (also called “lazy copy”) is a common optimization that uses reference counting. Do you know how to implement it? In this first Item, we consider a simple plain-vanilla String that's not reference-counted at all. In the rest of the miniseries, we'll see what impact adding copy-on-write semantics can have on the class.

Consider the following simplified String class. (Note: This is not intended to be a complete string facility. It's been distilled to serve as an example, and is missing many common operations that you would otherwise see in a real string class. In particular, I don't show operator=() because its code is essentially the same as that of copy construction.) ...

Get More Exceptional C++ now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.