Implementation Details

Implementing reference counting is a delicate, nontrivial task. The same goes for explaining it. Instead of re-inventing the wheel, we chose to base our performance discussion on the reference counting implementation developed by Meyers in item 29 of “More Effective C++” [Mey96], for several reasons:

  • It is an efficient implementation, given what it set out to accomplish.

  • It is explained very well in [Mey96]. You may refer to it for more details than we provide here.

  • Many people may already be familiar with this particular implementation.

Let's start with a Widget class and evolve it into a reference-counted one. The Widget class contains a member pointing to heap memory (Meyers uses a String class in his initial demonstration ...

Get Efficient C++ Performance Programming Techniques now with O’Reilly online learning.

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