Matthew R. Bisson

When Empty Base Optimization Goes “Wrong”

Occasionally, we use C++ inheritance to “tag” a class for some later purpose, or perhaps to introduce a functional change without copying code (e.g., boost::noncopyable). When the inherited class has no data, we (quite reasonably) expect to incur no run-time size overhead, due to Empty Base Optimization (EBO), but there is one surprising case where we must take care, or unintentionally waste memory. In this article, let’s explore the issue, and how to guard against it.

Continue reading “When Empty Base Optimization Goes “Wrong””