In article <f0kf3k$985$1@news.Stanford.EDU>, Seungbeom Kim
<musiphil@bawi.org> wrote:
What's the precise effect of "turning off RTTI" on typical
implementations? From what I've heard, virtual function calls are still
available even when RTTI is off, which means that vptr is still intact.
Then there's not much more to be saved by disabling other parts of RTTI,
is there? Because all the others would be per class, not per object.
Virtual functions are not ussually expensive to implement. [slower
than direct calls, but not overly expensive], There is no real reason
to
forbid them when forbidding RTTI.
Dynamic casts are ussually the most expensive C++ style cast and require
infromation about what classes a particular pointer to a given class
type is also a pointer to a different class type at run time and this
infromation is per object.
Contrived but consider this:
struct Base {virtual ~Base(){}};
struct A:Base {};
struct B:Base {};
struct C:Base{};
void f(A *);
void g(B *);
void foo(Base *p)
{
if(A * q= dynamic_cast<A *>(p))
f(q)
else if(B *q = dynamic_cast<B*>(p))
g(q);
}
now each Base * must contain infromation[ if it is also an A *, B *, or
C *] and this is per object.
No it's not. It can still be stored in the vtbl. In single inheritance
vtbl). In multiple inheritance, the cost would be one pointer per base
class, I think. It's still a constant factor *PER CLASS*, not per object.
[ comp.lang.c++.moderated. First time posters: Do this! ]