Title: Inside the C++ Object Model
Author:
Published: 1996
ISBN: 0-201-83454-5
Verdict: Recommended (even after 16 years)
I managed to pick this book up second hand from
Just a week or so ago the age old argument about C++ being bloated and inefficient reared its ugly head again. The answer it now seems is to point the protagonists to this book as Lippman cites this common myth in his preface as one reason for writing it. I agree with him that an understanding of the implementation helps with writing more efficient code from the get go as you know the costs of various language features.
The book is split into 7 chapters and starts with the fundamental Object Model – how an object is represented in memory. He doesn’t just cover what a v-table is, but instead walks through in detail how we got from a C style struct to a C++ polymorphic object, including such trade-offs as where to place the v-table. He makes continuous references to the evolution of Cfront which helps you understand the earlier constraints that drove the language.
Once the model is cemented he goes on to talk about constructors (default & copy), data members and then different types of functions (static, non-static & virtual) in the following 3 chapters. He covers the Named Return Value Optimisation in depth and provides some performance figures to back things up. What is particularly noticeable is the number of pages devoted to dealing with Virtual Base Classes – you’ll begin to understand why developers often shy away from them.
Chapter 5 looks at the semantics (rather than just the mechanics) of constructors and destructors and their effects on the compiler. Chapter 6 covers new & delete and the tricky issues that initialising arrays throw up. Plus he covers temporary objects in fine detail as that provides a common source of folklore it seems.
The final chapter looks at the then “new editions” to the language – Templates, Exception Handling and Runtime Type Identification (RTTI). Given its age this chapter is lighter on content, but the mechanics and lineage are still very useful. I also learnt another thing about name resolution within templates that really surprised me - this alone made purchasing it worth the price.
Chris Oldwood
12/10/2012