Sebastian Karlsson
2008-07-31 22:31:56 UTC
Hi, I'm kind of comparing RTTI vs a programmed type sytem of the type:
enum Type { blah, etc }
class Base
{
virtual Type GetType() const = 0;
}
For this type of system I would have to make a virtual function call,
in this regard I reckon RTTI will perform the same, or perhaps even
better. The problem is that the typeinfo object needs to be
constructed and returned, and it seems way more costly than a simple
enum.
My question really is, why was typeinfo designed like this? Wouldn't
it be better if typeinfo just was some typedef for a int, which should
be more than enough to uniquely represent all the possible classes in
even the largest system. If the user wants a string representation,
then surely that could've been accomplished with a function call using
the unique id. The only problem I see with this approach is when
linking with different libraries, but wouldn't the linker be able to
patch this up then anyway? Even as it is now typeinfo holds no
guarantee of being unique across compilers / platforms etc. Or have
some form of weak_typeid() operator with less guarantees. RTTI
could've been a perfect fit for me, in my use case I don't mind paying
for the slight memory overhead, I'm having a hard time justifying its
use due to the performance implications of the construction /
deconstruction of typeinfo.
enum Type { blah, etc }
class Base
{
virtual Type GetType() const = 0;
}
For this type of system I would have to make a virtual function call,
in this regard I reckon RTTI will perform the same, or perhaps even
better. The problem is that the typeinfo object needs to be
constructed and returned, and it seems way more costly than a simple
enum.
My question really is, why was typeinfo designed like this? Wouldn't
it be better if typeinfo just was some typedef for a int, which should
be more than enough to uniquely represent all the possible classes in
even the largest system. If the user wants a string representation,
then surely that could've been accomplished with a function call using
the unique id. The only problem I see with this approach is when
linking with different libraries, but wouldn't the linker be able to
patch this up then anyway? Even as it is now typeinfo holds no
guarantee of being unique across compilers / platforms etc. Or have
some form of weak_typeid() operator with less guarantees. RTTI
could've been a perfect fit for me, in my use case I don't mind paying
for the slight memory overhead, I'm having a hard time justifying its
use due to the performance implications of the construction /
deconstruction of typeinfo.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]