December 2001
Intermediate to advanced
304 pages
6h 25m
English
Difficulty: 3
Copy-on-write is a common optimization. Do you know how to implement it?
Original::String (from Item 13) is all very well, but sometimes copies of string objects are taken, used without modification, and then discarded.
“It seems a shame,” the implementer of Original::String from Item 13 might frown to herself, “that I always do all the work of allocating a new buffer (which can be expensive) when it may turn out that I never needed to if all the user does is read from the new string and then destroy it. I could have simply let the two string objects share a buffer under the covers, avoiding the copy for a while, and only really take a copy when I know I need to because one ...
Read now
Unlock full access