From Stroustrup's Foundations of C++, he offers a pure object-oriented language (on Page 4).
class complex { double re, im; /* … */ };
complex a[ ] = { {1,2}, {3,4} };
He assumes a
in the pure object-oriented language is allocated on the heap, and a
's memory layout looks like:
The likely size is 3*sizeof(reference)+3*sizeof(heap_overhead)+4*sizeof(double). Assuming a reference to be one word and the heap overhead to be two words, we get a likely size of 19 words to compare to C++’s 8 words. This memory overhead comes with a run-time overhead from allocation and indirect access to elements. That indirect access to memory typically causes problems with cache utilization and limits ROMability.
I noticed that the uppermost reference has no heap overhead (white rectangle).
I guess it is a general phenomenon rather than specified for the pure OO example language.
But I cannot find any reference (I do admit this is not a search-engine-friendly question).
Update
Thanks for your answers. However, I forgot to post my original guess. (Apologies, it is my fault.)
Actually, I also thought because a
itself may be allocated on the stack or somewhere else, it will not have heap overhead itself. But later, I noted BS also says:
Compare this with a more typical layout from a “pure object-oriented language” where
each user-defined object is allocated separately on the heap
and accessed through a reference...
on Page 4.
So, I think that he has limited the implementation to heap-only (or stack-less).
(Of course, maybe I'm reading too much into this sentence.)