Hi Ulrich, Well of course a dynamic_cast is not always repleacable by a className() call. This happens only sometimes. My bench' only says "if you can, then use className()" and also says "use dynamic_cast wisely: it costs a lot".
And about the static_cast in the bench', you're right, but I'm not sure this has any performance impact since the type is only an information for the compiler. Only the affectation would cost something I think. Well... I'm going to test. (...) Result: that's right, I can't see any difference. So you're code is cleaner than mine, but there is no noticeable effect on performance. Thank you! Sukender PVLE - Lightweight cross-platform game engine - http://pvle.sourceforge.net/ > Quoting Sukender <[EMAIL PROTECTED]>: >> Has anyone *benchmarked* the difference between a dynamic_cast and a virtual >> call to identify the type of a class? Before my benchmark, I guessed the >> virtual call was cheaper, but how much? I just knew it depends a lot on how >> types are related for the dynamic_cast. > > interesting results, I wouldn't have thought it'd be that different. > > However when doing a dynamic_cast you probably don't want to check for exact > type (which is what the name compare is doing) but rather find out if an > object > supports a certain interface i.e. is derived from a specific base class. You > simply can't do that by checking the class name. > > Also for consistency you should add (and time) a static_cast<> after your > strcmp > to get a pointer to the actual data type: > > if (pointer->className() == "Target") { > Target* t = static_cast<Target*>(pointer); > } > > Cheers, > /ulrich > _______________________________________________ > osg-users mailing list > [email protected] > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org _______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

