public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* virtual inheritance: optimization for empty objects
@ 1999-03-04 12:56 Alexander Schiemann
  1999-03-31 23:46 ` Alexander Schiemann
  0 siblings, 1 reply; 20+ messages in thread
From: Alexander Schiemann @ 1999-03-04 12:56 UTC (permalink / raw)
  To: egcs



^ permalink raw reply	[flat|nested] 20+ messages in thread
* virtual inheritance: optimization for empty objects
@ 1999-03-04 13:05 Alexander Schiemann
  1999-03-04 13:39 ` Alexandre Oliva
  1999-03-31 23:46 ` Alexander Schiemann
  0 siblings, 2 replies; 20+ messages in thread
From: Alexander Schiemann @ 1999-03-04 13:05 UTC (permalink / raw)
  To: egcs

Hi,

deriving a class B from class A without adding a data-member
does not increase the size.
But with virtual inheritance egcs-1.1.1 does not take advantage
of such a situation. Of course, some virtual pointer had to
be added. But we need only the locations of non-empty blocks
of data assigned to some virtual bases. 
The easiest example is the following multiple derivation:

struct A{
int a; // some data
};

struct B1:virtual A{}; // no additional data

struct B2:virtual A{}; // no additional data

struct C:public B1,public B2{};

We get the sizes:
sizeof A=4
sizeof B1=8
sizeof B2=8
sizeof C=12

So we have two redundant virtual pointers in C.
We could let B1 and B2 overlap in C (both consist of the
same virtual pointer).
With additional levels of virtual bases the possible gain
increases quickly. Even if only some of the derived classes do not
add data it seems possible (though not entirely trivial) to
get rid of many of the virtual pointers.

I think that quite frequently abstract classes consist only of 
virtual functions. I encountered this situation modeling hierarchies
of mathematical objects (that have a partial order of generalization).
In this context every base-class occurs once in an object and only the
lowest base-class and the most derived classes have some data. 
 
Now I would like to know
- does this suggestion conform with the standard (two base subobjects
  having the same address)? I checked it, but perhaps
  I missed some requirement.
- are there compilers that implement this kind of layout?


Thanks
Alexander Schiemann

^ permalink raw reply	[flat|nested] 20+ messages in thread
[parent not found: <199903042105.WAA19132.cygnus.egcs@count.math.uni-sb.de>]
[parent not found: <nms.mail.egcs/199903042105.WAA19132@count.math.uni-sb.de>]

end of thread, other threads:[~1999-03-31 23:46 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-03-04 12:56 virtual inheritance: optimization for empty objects Alexander Schiemann
1999-03-31 23:46 ` Alexander Schiemann
1999-03-04 13:05 Alexander Schiemann
1999-03-04 13:39 ` Alexandre Oliva
1999-03-31 23:46   ` Alexandre Oliva
1999-03-31 23:46 ` Alexander Schiemann
     [not found] <199903042105.WAA19132.cygnus.egcs@count.math.uni-sb.de>
1999-03-06 17:09 ` Jason Merrill
1999-03-31 23:46   ` Jason Merrill
     [not found] <nms.mail.egcs/199903042105.WAA19132@count.math.uni-sb.de>
     [not found] ` <nms.mail.egcs/orn21tueds.fsf@araguaia.dcc.unicamp.br>
1999-03-14 11:01   ` Marc Girod
1999-03-14 11:15     ` Alexandre Oliva
     [not found]       ` < orlngz3n0r.fsf@dcc.unicamp.br >
1999-03-15  3:44         ` F. Heitkamp
     [not found]           ` < 199903151145.GAA14544@pc1.fred.org >
1999-03-15 16:07             ` Martin v. Loewis
1999-03-31 23:46               ` Martin v. Loewis
1999-03-31 23:46           ` F. Heitkamp
1999-03-31 23:46       ` Alexandre Oliva
     [not found]     ` < 1yk8wjdhf7.fsf@sinkku.ntc.nokia.com >
1999-03-14 11:45       ` Joe Buck
1999-03-31 23:46         ` Joe Buck
1999-03-14 11:52       ` Martin v. Loewis
1999-03-31 23:46         ` Martin v. Loewis
1999-03-31 23:46     ` Marc Girod

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).