Re: Keeping Track Of Classes
Posted: Sun Oct 04, 2009 4:43 pm
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.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)) {
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?