Possible Duplicate:
C++ virtual function table memory cost
I’ve juste read that : http://www.parashift.com/c++-faq-lite/virtual-functions.html and I wonder what is the memory overhead due to virtuality.
I’m currently writing an optimized code for supercomputers, and I have to find the good balance between a readable code and memory consumption.
In order to understand how it works what would be the memory overhead for the following classes :
class AbstractA {/* SOMETHING */};
class AbstractB {/* SOMETHING */};
class A : public AbstractA {/* SOMETHING */};
class B : public AbstractB {/* SOMETHING */};
class A2 : public A {/* SOMETHING */};
class B2 : public B {/* SOMETHING */};
class AbstractAB : public AbstractA, public AbstractB {/* SOMETHING */};
class AbstractAB2 : public AbstractAB {/* SOMETHING */};
Suppose that I have one billion objects of each class, I have to bother about non-static memory consumption. So how much will it be for each object type ? (if each virtual method of AbstractA will create a pointer for each object of type “A”, I die…)
You might wanna look at Item 24 of Scott Meyer’s More Effective C++. It is titled ‘Understand the costs of virtual functions, multiple inheritance, virtual base class and RTTI ‘. In this item Meyers goes over the overhead involved in making use of these facilities.