How are C++ objects laid out in memory?
Like C, C++ doesn’t define layouts, just semantic constraints that must be met. Therefore different implementations do things differently. Unfortunately, the best explanation I know of is in a book that is otherwise outdated and doesn’t describe any current C++ implementation: The Annotated C++ Reference Manual (usually called the ARM). It has diagrams of key layout examples. There is a very brief explanation in Chapter 2 of TC++PL. Basically, C++ constructs objects simply by concatenating sub objects.
Related Questions
- In order to save memory, two instances of the following wrapper objects will always be == when their primitive values are the same. Please read Why does the autoboxing conversion sometimes return the same reference?
- Can I run Datamine processes on data objects in memory?
- How are C++ objects laid out in memory?