C++ : How can I know the size of Base class SubObject? -


.

here discussing empty base optimization, , msalters made interesting comment:

no class can ever have sizeof(class)==0, empty or not. but we're talking on size of empty base class subobject. doesn't need own vtable, nor vtable pointer. assume common layout of vtable pointer @ offset 0; cause zero-sized base class subobject share vtable pointer derived class. no problem: should identical anyway, that's pretty point of virtual functions.

my question this: compiler may optimize when use empty class base class, or may not. how determine does?

and in general, how can know size of base class subobject? size of base subobject same irrespective of whether use base or not? compilers optimize empty base classes?

.

good answers.

by way, ms vc++ , g++ compilers can dump class layouts study.

with vc++ run cl.exe /c /d1reportallclasslayout <source>.cpp

this uses class , vtable layout dump code wrote in 1990 test proper layout objects, vtables, vbtables, etc.

to better understand how c++ compilers lay out objects in memory, might enjoy http://www.openrce.org/articles/files/jangrayhood.pdf , stan lippman's book inside c++ object model.

happy hacking!


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -