Re: Memory layout of derived classes when using single inheritance.
Richard Corden ha scritto:
Hi,
I'm trying to get my head around some of the paragraph at the beginning
of chapter 10.
Firstly I'm trying to understand 10/3. When it uses the term 'order in
which the base class subobjects are allocated', what order is it
referring to? I think it implies *when* the base class subobjects are
allocated, rather than *where*.
I think it clearly implies *where*. There is no notion of time here,
10/3 is about how subobjects are laid out in memory, not the sequence of
events that bring those objects into existence (that is the subject of 3.8).
Another argument against the "when" interpretation is that the memory of
the whole most derived object is allocated in one operation and then
split into subobjects. The splitting step doesn't require any runtime
decision (because the layout is determined at compile time), so, in a
certain sense, all subobjects are allocated simultaneously.
A second question I have relates to 10/5, where it has a note which
mentions that a base class subobject may have a different layout to that
of a most derived object of the same type. Under what kind of
conditions can this be true?
The wording here is explicitly granting latitude for both known and
future (not-yet-known) optimizations, so there's no definitive answer to
your question. Specific implementations may (and usually do) provide
documentation of class layout strategies, so if you are interested you
should read those.
Regards,
Ganesh
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]