Keeping Track Of Classes

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

internetfx
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 11
Joined: Mon Sep 28, 2009 1:11 am

Re: Keeping Track Of Classes

Post by internetfx »

MarauderIIC wrote:dynamic_casting something to its own type would seem the fastest thing in general, and it's still 10x slower. Perhaps I'm misunderstanding what you mean when you say "single-level hierarchy". You mean a class that's not derived from anything else being cast to itself? I would have thought that dynamic_cast would start at the bottom and traverse the inheritance tree upwards.

Code: Select all

osg::Node * p = new osg::MatrixTransform;...
    if (dynamic_cast<osg::MatrixTransform*>(p)) {
You're right, it would be upward traversal; I just didn't see that the speed tests stated specifically that a class was being "cast to itself" or that those are actual comparisons that we are stating all these supposed speed comparisons on: between checking the type manually from a class member vs. a virtual function call vs. dynamic_cast<>. I guess it's an exercise to try.

But I would focus on optimization settings: these tests may not really be performed the way one would expect. If debugging code is generated, there could be some useless stuff happening in dynamic_cast<> just for debugging purposes that would be unnecessary in an optimized non-debug compile. I'd like to see the assembly generated just to know what, for 10x the time, is so important that has to happen in a dynamic_cast<>, because I question, why the hell is it so slow if a dynamic_cast<> is casting a type to itself?

What is actually happening in that case, in the assembly?
Post Reply