Thread: RE: [GD-General] Overhead of RTTI
Brought to you by:
vexxed72
From: Tom F. <to...@mu...> - 2002-12-24 13:02:59
|
It's usually far quicker and easier to code it yourself with a few helper functions, unless you actually need the full madness of RTTI. Tom Forsyth - Muckyfoot bloke and Microsoft MVP. This email is the product of your deranged imagination, and does not in any way imply existence of the author. > -----Original Message----- > From: Adrian Cearnau [mailto:ce...@ce...] > Sent: 24 December 2002 12:50 > To: gam...@li... > Subject: [GD-General] Overhead of RTTI > > > Hey everyone and merry X-Mas, > > I'd like to know what the realistic overhead of enabling RTTI in a C++ > project is. Any opinions are welcome. > > Thank you, > Adrian 'cearny' Cearnau |
From: Grills, J. <jg...@so...> - 2002-12-24 13:49:48
|
I think it somewhat depends on your compiler. Two of the larger profile spikes in a Win32 compile (using MSVC 6) of one of our applications right now are caused by excessive use of dynamic_cast. I spent some time looking at the code dynamic_cast created, and it's ugly. It even does string compares internally, which is completely gross. For places where performance matters, we are adding a "virtual Derived * asDerivedClass()" function which returns NULL in the base class and "this" in the Derived class. Tracking down inappropriate frequent callers of dynamic_cast can be pretty tedious as well. GCC's code gen for this stuff is apparently a fair bit better. j -----Original Message----- From: Tom Forsyth [mailto:to...@mu...] Sent: Tuesday, December 24, 2002 7:02 AM To: gam...@li... Subject: RE: [GD-General] Overhead of RTTI It's usually far quicker and easier to code it yourself with a few helper functions, unless you actually need the full madness of RTTI. Tom Forsyth - Muckyfoot bloke and Microsoft MVP. This email is the product of your deranged imagination, and does not in any way imply existence of the author. > -----Original Message----- > From: Adrian Cearnau [mailto:ce...@ce...] > Sent: 24 December 2002 12:50 > To: gam...@li... > Subject: [GD-General] Overhead of RTTI > > > Hey everyone and merry X-Mas, > > I'd like to know what the realistic overhead of enabling RTTI in a C++ > project is. Any opinions are welcome. > > Thank you, > Adrian 'cearny' Cearnau |
From: Grills, J. <jg...@so...> - 2002-12-24 13:54:52
|
I didn't quite understand your email, so this comment may not apply to your case. You can't dynamic_cast<> from a void*. You have to have an object that has a virtual function in it, and you should be casting from a base class of the desired target. And, as a general rule, multiple inheritance is evil and should be avoided. In fact, we've recently put a rule in place where any use of multiple inheritance requires a lead programmer's permission before submitting to source control. j -----Original Message----- From: Adrian Cearnau [mailto:ce...@ce...] Sent: Tuesday, December 24, 2002 7:26 AM To: gam...@li... Subject: RE: [GD-General] Overhead of RTTI Hey, It might be a bad design, but now that I've hit this problem, I'd also like to know why it happens and how much RTTI would *really* hurt. The class hierarchy in discussion has a base Obect class that has a name field and is virtually inherited by all the other classes in the hierarchy. Now I have a Texture class and a RenderTarget class (buth abstract), and in the implementation I have a (say) D3DTexture class that inherits both Texture and RenderTarget. The problem is that the RenderSystem class (the one that does the actual rendering) is pretty abstracted itself so it works with Textures and renderTargets. At some point I have to cast from Object to D3DTexture and there's where all hell brakes loose. I can't even cast from void * to D3DTexture for that matter (well, the void * was initially a RenderTarget cast of D3DTexture, so yes, it is a whole madness). My bet is on dynamic_cast or modifying the design (I'll probably choose the latter eventually). Seems like hard abstraction would be way easier (and safer) with RTTI enabled. Thanks again, Adrian -----Original Message----- From: gam...@li... [mailto:gam...@li...] On Behalf Of Tom Forsyth Sent: Tuesday, December 24, 2002 3:02 PM To: gam...@li... Subject: RE: [GD-General] Overhead of RTTI It's usually far quicker and easier to code it yourself with a few helper functions, unless you actually need the full madness of RTTI. Tom Forsyth - Muckyfoot bloke and Microsoft MVP. This email is the product of your deranged imagination, and does not in any way imply existence of the author. > -----Original Message----- > From: Adrian Cearnau [mailto:ce...@ce...] > Sent: 24 December 2002 12:50 > To: gam...@li... > Subject: [GD-General] Overhead of RTTI > > > Hey everyone and merry X-Mas, > > I'd like to know what the realistic overhead of enabling RTTI in a C++ > project is. Any opinions are welcome. > > Thank you, > Adrian 'cearny' Cearnau ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ Gamedevlists-general mailing list Gam...@li... https://lists.sourceforge.net/lists/listinfo/gamedevlists-general Archives: http://sourceforge.net/mailarchive/forum.php?forum_id=557 ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ Gamedevlists-general mailing list Gam...@li... https://lists.sourceforge.net/lists/listinfo/gamedevlists-general Archives: http://sourceforge.net/mailarchive/forum.php?forum_id=557 |
From: Noel L. <ll...@co...> - 2002-12-24 14:04:15
|
On Tue, 24 Dec 2002 05:54:49 -0800 "Grills, Jeff" <jg...@so...> wrote: > And, as a general rule, multiple inheritance is evil and should be avoided. Whoa! Talk about an overblown general statement! I would say that multiple inheritance definitely has its place, in particular inheritance of abstract interfaces. > In fact, we've recently put a rule in place where any use of multiple > inheritance requires a lead programmer's permission before submitting to > source control. Do you have similar rules about using templates? What about classes that exceed 1000 lines of code? Both of those situations seem more potentially dangerous to me than using multiple inheritance. Just curious. Of course, on the other hand, in a large team it might be a good idea if before checking in any new classes or adding any new dependencies between classes a lead programmer approves it first, but that's a separate discussion. --Noel ll...@co... |
From: Nicolas R. <nic...@fr...> - 2002-12-24 14:30:52
|
Hi, > > And, as a general rule, multiple inheritance is evil and should be > > avoided. > > Whoa! Talk about an overblown general statement! > > I would say that multiple inheritance definitely has its > place, in particular inheritance of abstract interfaces. > Do not mix object inheritance, and interface expension / implementation. Though those are completely mixed (for evil sake) in C++, one must pay attention to be absolutely clear on how they are used. Objects should inherit at most ONE object, and implement as many interfaces as needed. Interfaces should expend at most ONE interface. A lot of inheritance problems we got in the past were due to a misunderstanding of those statements. On the RTTI subject, I really like to have all objects (and I say objects) implementing a RTTI scheme of our own, and providing interface access methods. Interfaces do need some kind of static identification, but usually RTTI is not needed at that point. Nicolas Romantzoff. |
From: Javier A. <ja...@py...> - 2002-12-24 16:21:54
|
Nicolas Romantzoff wrote: >>> And, as a general rule, multiple inheritance is evil and should be >>> avoided. >> >> Whoa! Talk about an overblown general statement! I'd like to add that I concur with the original post. One could say (grabs the number-filled hat) that 70% of MI uses are plainly bad and 20% are ok but can be done better in other ways (aggregation, etc). Note that I see inheriting multiple interfaces as something different from "general" MI. > Objects should inherit at most ONE object, and implement as many > interfaces as needed. > Interfaces should expend at most ONE interface. Can you explain more carefully? I didn't really understand the second rule. |
From: Nicolas R. <nic...@fr...> - 2002-12-24 16:47:14
|
> > Objects should inherit at most ONE object, and implement as many > > interfaces as needed. Interfaces should expend at most ONE > interface. > > Can you explain more carefully? I didn't really understand > the second rule. > That second rule is just to say that you never need MI at interface level. Just define separate interfaces. I'm even wondering if one would need inheritance for interfaces at all (apart from a "root" interface like the COM's IUnknown). Objects on the opposite do need MI for interface implementation. Here, we are trying to use different words for inheritance: Object To Object inheritance = Override (the "IS A" relationship). Object To Interface inheritance = Implementation. Interface To Interface inheritance = Expansion. (of course there is never any Interface To Object inheritance). Nicolas |
From: <ce...@ce...> - 2002-12-26 17:34:19
|
Okay, but does any of you know what other overhead will RTTI introduce if dynamic_cast will be used strictly when static_cast won't work (like when having to do with MI)? Maybe a structure size overhead, but how big? Thanks, Adrian -----Original Message----- From: gam...@li... [mailto:gam...@li...] On Behalf Of Nicolas Romantzoff Sent: Tuesday, December 24, 2002 6:47 PM To: gam...@li... Subject: RE: [GD-General] Overhead of RTTI > > Objects should inherit at most ONE object, and implement as many > > interfaces as needed. Interfaces should expend at most ONE > interface. > > Can you explain more carefully? I didn't really understand > the second rule. > That second rule is just to say that you never need MI at interface level. Just define separate interfaces. I'm even wondering if one would need inheritance for interfaces at all (apart from a "root" interface like the COM's IUnknown). Objects on the opposite do need MI for interface implementation. Here, we are trying to use different words for inheritance: Object To Object inheritance = Override (the "IS A" relationship). Object To Interface inheritance = Implementation. Interface To Interface inheritance = Expansion. (of course there is never any Interface To Object inheritance). Nicolas ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ Gamedevlists-general mailing list Gam...@li... https://lists.sourceforge.net/lists/listinfo/gamedevlists-general Archives: http://sourceforge.net/mailarchive/forum.php?forum_id=557 |
From: Mickael P. <gd...@dr...> - 2002-12-26 23:15:45
|
Hmm I hope you meant reinterpret_cast, otherwise I'd understand why you n= eed RTTI in order to make things work. ----- Original Message ----- From: "Adrian Cearn=E3u" <ce...@ce...> To: <gam...@li...> Sent: Thursday, December 26, 2002 6:34 PM Subject: RE: [GD-General] Overhead of RTTI > Okay, but does any of you know what other overhead will RTTI introduce > if dynamic_cast will be used strictly when static_cast won't work (like > when having to do with MI)? Maybe a structure size overhead, but how > big? > > Thanks, > Adrian > > -----Original Message----- > From: gam...@li... > [mailto:gam...@li...] On Behalf Of > Nicolas Romantzoff > Sent: Tuesday, December 24, 2002 6:47 PM > To: gam...@li... > Subject: RE: [GD-General] Overhead of RTTI > > > > > > Objects should inherit at most ONE object, and implement as many > > > interfaces as needed. Interfaces should expend at most ONE > > interface. > > > > Can you explain more carefully? I didn't really understand > > the second rule. > > > > That second rule is just to say that you never need MI at interface > level. > Just define separate interfaces. > I'm even wondering if one would need inheritance for interfaces at all > (apart from a "root" interface like the COM's IUnknown). > > Objects on the opposite do need MI for interface implementation. > > Here, we are trying to use different words for inheritance: > Object To Object inheritance =3D Override (the "IS A" relationship). > Object To Interface inheritance =3D Implementation. > Interface To Interface inheritance =3D Expansion. > (of course there is never any Interface To Object inheritance). > > > > Nicolas > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Gamedevlists-general mailing list > Gam...@li... > https://lists.sourceforge.net/lists/listinfo/gamedevlists-general > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_id=3D557 > > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Gamedevlists-general mailing list > Gam...@li... > https://lists.sourceforge.net/lists/listinfo/gamedevlists-general > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_id=3D557 > |
From: <ce...@ce...> - 2002-12-27 08:14:02
|
Oh yes sorry, too much vacation for my brain lately :) To explain, I need this when for example I have a MI class and at a point I cast it into one of the base classes and at a latter point I want to cast it into the initial derived class. The current workaround is to set the base class in which I cast as the first one from which my dervied class inherits, but is not exactly the right way I believe. -----Original Message----- From: gam...@li... [mailto:gam...@li...] On Behalf Of Mickael Putters Sent: Friday, December 27, 2002 1:13 AM To: gam...@li... Subject: Re: [GD-General] Overhead of RTTI Hmm I hope you meant reinterpret_cast, otherwise I'd understand why you need RTTI in order to make things work. ----- Original Message ----- From: "Adrian Cearn=E3u" <ce...@ce...> To: <gam...@li...> Sent: Thursday, December 26, 2002 6:34 PM Subject: RE: [GD-General] Overhead of RTTI > Okay, but does any of you know what other overhead will RTTI introduce > if dynamic_cast will be used strictly when static_cast won't work (like > when having to do with MI)? Maybe a structure size overhead, but how > big? > > Thanks, > Adrian > > -----Original Message----- > From: gam...@li... > [mailto:gam...@li...] On Behalf Of > Nicolas Romantzoff > Sent: Tuesday, December 24, 2002 6:47 PM > To: gam...@li... > Subject: RE: [GD-General] Overhead of RTTI > > > > > > Objects should inherit at most ONE object, and implement as many > > > interfaces as needed. Interfaces should expend at most ONE > > interface. > > > > Can you explain more carefully? I didn't really understand > > the second rule. > > > > That second rule is just to say that you never need MI at interface > level. > Just define separate interfaces. > I'm even wondering if one would need inheritance for interfaces at all > (apart from a "root" interface like the COM's IUnknown). > > Objects on the opposite do need MI for interface implementation. > > Here, we are trying to use different words for inheritance: > Object To Object inheritance =3D Override (the "IS A" relationship). > Object To Interface inheritance =3D Implementation. > Interface To Interface inheritance =3D Expansion. > (of course there is never any Interface To Object inheritance). > > > > Nicolas > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Gamedevlists-general mailing list > Gam...@li... > https://lists.sourceforge.net/lists/listinfo/gamedevlists-general > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_id=3D557 > > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Gamedevlists-general mailing list > Gam...@li... > https://lists.sourceforge.net/lists/listinfo/gamedevlists-general > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_id=3D557 > ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ Gamedevlists-general mailing list Gam...@li... https://lists.sourceforge.net/lists/listinfo/gamedevlists-general Archives: http://sourceforge.net/mailarchive/forum.php?forum_idU7 |
From: Idahosa I. O. E. <ida...@sw...> - 2002-12-26 06:41:41
|
What do you mean by the term expend? I thought I understood the word but obviously no in the context you use here. Idahosa Edokpayi O2Cool Games Software -----Original Message----- From: gam...@li... [mailto:gam...@li...] On Behalf Of Nicolas Romantzoff Sent: Tuesday, December 24, 2002 8:31 AM To: gam...@li... Subject: RE: [GD-General] Overhead of RTTI Hi, > > And, as a general rule, multiple inheritance is evil and should be > > avoided. > > Whoa! Talk about an overblown general statement! > > I would say that multiple inheritance definitely has its > place, in particular inheritance of abstract interfaces. > Do not mix object inheritance, and interface expension / implementation. Though those are completely mixed (for evil sake) in C++, one must pay attention to be absolutely clear on how they are used. Objects should inherit at most ONE object, and implement as many interfaces as needed. Interfaces should expend at most ONE interface. A lot of inheritance problems we got in the past were due to a misunderstanding of those statements. On the RTTI subject, I really like to have all objects (and I say objects) implementing a RTTI scheme of our own, and providing interface access methods. Interfaces do need some kind of static identification, but usually RTTI is not needed at that point. Nicolas Romantzoff. ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ Gamedevlists-general mailing list Gam...@li... https://lists.sourceforge.net/lists/listinfo/gamedevlists-general Archives: http://sourceforge.net/mailarchive/forum.php?forum_id=557 |
From: Nicolas R. <nic...@fr...> - 2002-12-26 09:05:36
|
Hi ! Of course, I meant exTend (extension, extending, ...). My english has gone away with xmas... :) Nicolas. > -----Original Message----- > From: gam...@li... > [mailto:gam...@li...] On > Behalf Of Idahosa I. O. Edokpayi > Sent: Thursday, December 26, 2002 7:42 AM > To: gam...@li... > Subject: RE: [GD-General] Overhead of RTTI > > > What do you mean by the term expend? I thought I understood > the word but obviously no in the context you use here. > > Idahosa Edokpayi > O2Cool Games Software > > |
From: Nicolas R. <nic...@fr...> - 2002-12-24 13:55:16
|
Hi, Built-in RTTI is well suited for complex inheritance diagrams, but its overhead is not neglectable (just like C++ exception handling). I'm using exactly the same "kind" of hierarchy, banning multiple inheritance, and just adding a few things: The "Object" class is declared as: { public: static ObjectClass itsClass; virtual ObjectClass* GetClass(void) const { return &thisObjectClass; } inline const char* GetClassName(void) const { return GetClass()->Name(); } inline bool IsOfClass(const ObjectClass& oc) const { return (GetClass() == &oc); } }; Inherited classes (that do need RTTI) do also have: { public: Static ObjectClass itsClass; virtual ObjectClass* GetClass(void) const { return &thisObjectClass; } }; Whenever you want to check for an object being of a given class (something like your rendering device checking that the vertex buffer pointer is a D3D vertex buffer), you just have to call the GetClass and check returned value with the D3D::thisClass. (Or in the exemple above, using the IsOfClass method). Note that the above implementation is nice since it is still safe to use the RTTI methods in constructors/destructors. It turned out (for me) to be faster than built-in RTTI system, and a lot smaller (in terms of code/memory usage). Of course, my implementation is a bit more complicated, with ObjectClass constructors building the class hierarchy, making possible to check for inheritance, or more complex behaviors, maintaining a constructor list (for dynamic construction), and things like that... The "thisClass" object is also a nice place to put static tweakable values. The nice thing is that you can "forget" your own RTTI declaration where it is not needed (for example abstract class you don't need to know about), saving some memory/code-size (and eventually speed when checking for inheritance). Using macros like RTTI_DECLARE usually makes life easier in that case :) #define RTTI_DECLARE_EX(cloname) public: \ static cloname _class; \ virutal ObjectClass* GetClass(void) const { return &_class; } #define RTTI_DECLARE RTTI_DECLARE_EX(ObjectClass) Nicolas Romantzoff |
From: Tom F. <to...@mu...> - 2002-12-24 13:59:50
|
The easy, if rather messy and special-cased way, is to have a whole load of functions like this all the way down the hierarchy: virtual D3DTexture *MyCoolClass::GetD3DTexture ( void ) { // I'm not a D3DTexture you fool. return NULL; } ...but then for the D3DTexture class it's virtual D3DTexture *D3DTexture::GetD3DTexture ( void ) { return this; } Now sure, this pollutes your namespace with lots of GetMyFunkyClassName() calls, but if that's all you need to do, it's robust and pretty easy to understand, and doesn't require any RTTI support. Tom Forsyth - Muckyfoot bloke and Microsoft MVP. This email is the product of your deranged imagination, and does not in any way imply existence of the author. > -----Original Message----- > From: Adrian Cearnau [mailto:ce...@ce...] > Sent: 24 December 2002 13:26 > To: gam...@li... > Subject: RE: [GD-General] Overhead of RTTI > > > Hey, > > It might be a bad design, but now that I've hit this problem, I'd also > like to know why it happens and how much RTTI would *really* hurt. The > class hierarchy in discussion has a base Obect class that has a name > field and is virtually inherited by all the other classes in the > hierarchy. Now I have a Texture class and a RenderTarget class (buth > abstract), and in the implementation I have a (say) D3DTexture class > that inherits both Texture and RenderTarget. The problem is that the > RenderSystem class (the one that does the actual rendering) is pretty > abstracted itself so it works with Textures and renderTargets. At some > point I have to cast from Object to D3DTexture and there's where all > hell brakes loose. I can't even cast from void * to > D3DTexture for that > matter (well, the void * was initially a RenderTarget cast of > D3DTexture, so yes, it is a whole madness). My bet is on > dynamic_cast or > modifying the design (I'll probably choose the latter > eventually). Seems > like hard abstraction would be way easier (and safer) with > RTTI enabled. > > Thanks again, > Adrian > > -----Original Message----- > From: gam...@li... > [mailto:gam...@li...] On Behalf Of > Tom Forsyth > Sent: Tuesday, December 24, 2002 3:02 PM > To: gam...@li... > Subject: RE: [GD-General] Overhead of RTTI > > It's usually far quicker and easier to code it yourself with a few > helper > functions, unless you actually need the full madness of RTTI. > > Tom Forsyth - Muckyfoot bloke and Microsoft MVP. > > This email is the product of your deranged imagination, > and does not in any way imply existence of the author. > > > -----Original Message----- > > From: Adrian Cearnau [mailto:ce...@ce...] > > Sent: 24 December 2002 12:50 > > To: gam...@li... > > Subject: [GD-General] Overhead of RTTI > > > > > > Hey everyone and merry X-Mas, > > > > I'd like to know what the realistic overhead of enabling > RTTI in a C++ > > project is. Any opinions are welcome. > > > > Thank you, > > Adrian 'cearny' Cearnau > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Gamedevlists-general mailing list > Gam...@li... > https://lists.sourceforge.net/lists/listinfo/gamedevlists-general > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_id=557 > > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Gamedevlists-general mailing list > Gam...@li... > https://lists.sourceforge.net/lists/listinfo/gamedevlists-general > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_id=557 > |
From: Cruise <cr...@ca...> - 2002-12-24 14:08:13
|
>The easy, if rather messy and special-cased way, is to have a= whole load of >functions like this all the way down the hierarchy: > >virtual D3DTexture *MyCoolClass::GetD3DTexture ( void ) >{ >=A0=A0=A0=A0// I'm not a D3DTexture you fool. >=A0=A0=A0=A0return NULL; >} > > >....but then for the D3DTexture class it's > >virtual D3DTexture *D3DTexture::GetD3DTexture ( void ) >{ >=A0=A0=A0=A0return this; >} > > >Now sure, this pollutes your namespace with lots of= GetMyFunkyClassName() >calls, but if that's all you need to do, it's robust and pretty= easy to >understand, and doesn't require any RTTI support. > > >Tom Forsyth - Muckyfoot bloke and Microsoft MVP. > >This email is the product of your deranged imagination, >and does not in any way imply existence of the author. > This obviously can be restricted to only the classes that you= need to get the specific class pointer for. Half-Life used this method within it's game entity hierarchy, but= restricted it to only two classes/functions: MyMonsterPointer() and MySquadMonsterPointer() which did exactly as Tom described above for CBaseMonster and= CBaseSquadMonster respectively. If you have a reasonably flat hierarchy, and this functionality= is only required for a few classes, then it's not too ugly, and= is probably about as fast/efficient/safe as you could get this= sort of thing. [ cruise / casual-tempest.net / transference.org ] |
From: Tom F. <to...@mu...> - 2002-12-24 14:12:12
|
I'm talking rubbish of course - you don't need a whole load of GetD3DTexture functions, just one in the base class and one in D3DTexture itself. Doh. Brain not in gear... Tom Forsyth - Muckyfoot bloke and Microsoft MVP. This email is the product of your deranged imagination, and does not in any way imply existence of the author. > -----Original Message----- > From: Tom Forsyth [mailto:to...@mu...] > Sent: 24 December 2002 13:58 > To: gam...@li... > Subject: RE: [GD-General] Overhead of RTTI > > > The easy, if rather messy and special-cased way, is to have a > whole load of > functions like this all the way down the hierarchy: > > virtual D3DTexture *MyCoolClass::GetD3DTexture ( void ) > { > // I'm not a D3DTexture you fool. > return NULL; > } > > > ...but then for the D3DTexture class it's > > virtual D3DTexture *D3DTexture::GetD3DTexture ( void ) > { > return this; > } > > > Now sure, this pollutes your namespace with lots of > GetMyFunkyClassName() > calls, but if that's all you need to do, it's robust and > pretty easy to > understand, and doesn't require any RTTI support. > > > Tom Forsyth - Muckyfoot bloke and Microsoft MVP. > > This email is the product of your deranged imagination, > and does not in any way imply existence of the author. > > > -----Original Message----- > > From: Adrian Cearnau [mailto:ce...@ce...] > > Sent: 24 December 2002 13:26 > > To: gam...@li... > > Subject: RE: [GD-General] Overhead of RTTI > > > > > > Hey, > > > > It might be a bad design, but now that I've hit this > problem, I'd also > > like to know why it happens and how much RTTI would > *really* hurt. The > > class hierarchy in discussion has a base Obect class that has a name > > field and is virtually inherited by all the other classes in the > > hierarchy. Now I have a Texture class and a RenderTarget class (buth > > abstract), and in the implementation I have a (say) D3DTexture class > > that inherits both Texture and RenderTarget. The problem is that the > > RenderSystem class (the one that does the actual rendering) > is pretty > > abstracted itself so it works with Textures and > renderTargets. At some > > point I have to cast from Object to D3DTexture and there's where all > > hell brakes loose. I can't even cast from void * to > > D3DTexture for that > > matter (well, the void * was initially a RenderTarget cast of > > D3DTexture, so yes, it is a whole madness). My bet is on > > dynamic_cast or > > modifying the design (I'll probably choose the latter > > eventually). Seems > > like hard abstraction would be way easier (and safer) with > > RTTI enabled. > > > > Thanks again, > > Adrian > > > > -----Original Message----- > > From: gam...@li... > > [mailto:gam...@li...] > On Behalf Of > > Tom Forsyth > > Sent: Tuesday, December 24, 2002 3:02 PM > > To: gam...@li... > > Subject: RE: [GD-General] Overhead of RTTI > > > > It's usually far quicker and easier to code it yourself with a few > > helper > > functions, unless you actually need the full madness of RTTI. > > > > Tom Forsyth - Muckyfoot bloke and Microsoft MVP. > > > > This email is the product of your deranged imagination, > > and does not in any way imply existence of the author. > > > > > -----Original Message----- > > > From: Adrian Cearnau [mailto:ce...@ce...] > > > Sent: 24 December 2002 12:50 > > > To: gam...@li... > > > Subject: [GD-General] Overhead of RTTI > > > > > > > > > Hey everyone and merry X-Mas, > > > > > > I'd like to know what the realistic overhead of enabling > > RTTI in a C++ > > > project is. Any opinions are welcome. > > > > > > Thank you, > > > Adrian 'cearny' Cearnau > > > > > > > > ------------------------------------------------------- > > This sf.net email is sponsored by:ThinkGeek > > Welcome to geek heaven. > > http://thinkgeek.com/sf > > _______________________________________________ > > Gamedevlists-general mailing list > > Gam...@li... > > https://lists.sourceforge.net/lists/listinfo/gamedevlists-general > > Archives: > > http://sourceforge.net/mailarchive/forum.php?forum_id=557 > > > > > > > > > > ------------------------------------------------------- > > This sf.net email is sponsored by:ThinkGeek > > Welcome to geek heaven. > > http://thinkgeek.com/sf > > _______________________________________________ > > Gamedevlists-general mailing list > > Gam...@li... > > https://lists.sourceforge.net/lists/listinfo/gamedevlists-general > > Archives: > > http://sourceforge.net/mailarchive/forum.php?forum_id=557 > > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Gamedevlists-general mailing list > Gam...@li... > https://lists.sourceforge.net/lists/listinfo/gamedevlists-general > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_id=557 > |
From: Tom F. <to...@mu...> - 2002-12-24 14:12:34
|
I would modify that to: "inheritance of multiple virtual classes is evil". Multiple inheritance is just fine and dandy, as long as only one (or none) of the parent classes is a virtual class. Tom Forsyth - Muckyfoot bloke and Microsoft MVP. This email is the product of your deranged imagination, and does not in any way imply existence of the author. > -----Original Message----- > From: Grills, Jeff [mailto:jg...@so...] > Sent: 24 December 2002 13:55 > To: 'gam...@li...' > Subject: RE: [GD-General] Overhead of RTTI > > > > I didn't quite understand your email, so this comment may not > apply to your > case. You can't dynamic_cast<> from a void*. You have to > have an object > that has a virtual function in it, and you should be casting > from a base > class of the desired target. > > And, as a general rule, multiple inheritance is evil and > should be avoided. > In fact, we've recently put a rule in place where any use of multiple > inheritance requires a lead programmer's permission before > submitting to > source control. > > j > > -----Original Message----- > From: Adrian Cearnau [mailto:ce...@ce...] > Sent: Tuesday, December 24, 2002 7:26 AM > To: gam...@li... > Subject: RE: [GD-General] Overhead of RTTI > > > Hey, > > It might be a bad design, but now that I've hit this problem, I'd also > like to know why it happens and how much RTTI would *really* hurt. The > class hierarchy in discussion has a base Obect class that has a name > field and is virtually inherited by all the other classes in the > hierarchy. Now I have a Texture class and a RenderTarget class (buth > abstract), and in the implementation I have a (say) D3DTexture class > that inherits both Texture and RenderTarget. The problem is that the > RenderSystem class (the one that does the actual rendering) is pretty > abstracted itself so it works with Textures and renderTargets. At some > point I have to cast from Object to D3DTexture and there's where all > hell brakes loose. I can't even cast from void * to > D3DTexture for that > matter (well, the void * was initially a RenderTarget cast of > D3DTexture, so yes, it is a whole madness). My bet is on > dynamic_cast or > modifying the design (I'll probably choose the latter > eventually). Seems > like hard abstraction would be way easier (and safer) with > RTTI enabled. > > Thanks again, > Adrian > > -----Original Message----- > From: gam...@li... > [mailto:gam...@li...] On Behalf Of > Tom Forsyth > Sent: Tuesday, December 24, 2002 3:02 PM > To: gam...@li... > Subject: RE: [GD-General] Overhead of RTTI > > It's usually far quicker and easier to code it yourself with a few > helper > functions, unless you actually need the full madness of RTTI. > > Tom Forsyth - Muckyfoot bloke and Microsoft MVP. > > This email is the product of your deranged imagination, > and does not in any way imply existence of the author. > > > -----Original Message----- > > From: Adrian Cearnau [mailto:ce...@ce...] > > Sent: 24 December 2002 12:50 > > To: gam...@li... > > Subject: [GD-General] Overhead of RTTI > > > > > > Hey everyone and merry X-Mas, > > > > I'd like to know what the realistic overhead of enabling > RTTI in a C++ > > project is. Any opinions are welcome. > > > > Thank you, > > Adrian 'cearny' Cearnau > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Gamedevlists-general mailing list > Gam...@li... > https://lists.sourceforge.net/lists/listinfo/gamedevlists-general > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_id=557 > > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Gamedevlists-general mailing list > Gam...@li... > https://lists.sourceforge.net/lists/listinfo/gamedevlists-general > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_id=557 > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Gamedevlists-general mailing list > Gam...@li... > https://lists.sourceforge.net/lists/listinfo/gamedevlists-general > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_id=557 > |
From: Thatcher U. <tu...@tu...> - 2002-12-31 06:25:24
|
On Dec 24, 2002 at 02:11 -0000, Tom Forsyth wrote: > I would modify that to: "inheritance of multiple virtual classes is evil". > Multiple inheritance is just fine and dandy, as long as only one (or none) > of the parent classes is a virtual class. Ooh, this is one of my hot buttons! The "correct" (according to me :) statement is: Inheritance of multiple virtual classes is virtuous. Multiple inheritance is just fine and dandy, as long as ALL of the ancestor classes are virtual parents. MI of NON-virtual classes is where things get intolerably fubared. (I can expand on this or provide pointers if necessary.) Unfortunately, this situation makes it pretty damn confusing to maintain optimal use of "virtual public" and plain "public" throughout a hierarchy, in a team environment. My private thoughts these days are tending towards "MI is evil". -- Thatcher Ulrich http://tulrich.com |
From: Grills, J. <jg...@so...> - 2002-12-24 14:43:14
|
I think it's a good general rule. I never said it was an absolute, mind you, just a general rule. My experience with game programmers is that MI is most often misused. Sure, it has appropriate applications, but I'd bet at least 90% of the MI use in our game is ill-founded. Actually, it's funny that you mention templates. We are seriously debating a rule about templated classes in headers requiring lead permissions as well. They substantially increase build times, dependencies, and a host of other evil problems. In fact, we just ran into a problem where MSVC 6's PDB format is limited to 64mb, and one of our largest applications will no longer link with full debugging information because of it. I've done some analysis of the PDB contents, and about 27mb of that are text strings containing symbol names with "_STL" in them. Unless compiler/linker support for templates improves significantly, I really think that one day in the future, we'll look back on C++, templates and the STL and say, "What in the hell were we thinking?!?". And yes, we have a large team of 13 programmers. j -----Original Message----- From: Noel Llopis [mailto:ll...@co...] Sent: Tuesday, December 24, 2002 8:04 AM To: gam...@li... Subject: Re: [GD-General] Overhead of RTTI On Tue, 24 Dec 2002 05:54:49 -0800 "Grills, Jeff" <jg...@so...> wrote: > And, as a general rule, multiple inheritance is evil and should be avoided. Whoa! Talk about an overblown general statement! I would say that multiple inheritance definitely has its place, in particular inheritance of abstract interfaces. > In fact, we've recently put a rule in place where any use of multiple > inheritance requires a lead programmer's permission before submitting to > source control. Do you have similar rules about using templates? What about classes that exceed 1000 lines of code? Both of those situations seem more potentially dangerous to me than using multiple inheritance. Just curious. Of course, on the other hand, in a large team it might be a good idea if before checking in any new classes or adding any new dependencies between classes a lead programmer approves it first, but that's a separate discussion. --Noel ll...@co... ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ Gamedevlists-general mailing list Gam...@li... https://lists.sourceforge.net/lists/listinfo/gamedevlists-general Archives: http://sourceforge.net/mailarchive/forum.php?forum_id=557 |
From: Noel L. <ll...@co...> - 2002-12-24 15:40:09
|
On Tue, 24 Dec 2002 06:43:11 -0800 "Grills, Jeff" <jg...@so...> wrote: > My experience with game programmers is that MI is > most often misused. Sure, it has appropriate applications, but I'd bet at > least 90% of the MI use in our game is ill-founded. That's very true. I would also extend that statement to apply to single inheritance, but that's just me ;-) --Noel ll...@co... |
From: brian h. <bri...@py...> - 2002-12-24 17:22:45
|
> I really think that one day in the future, we'll look back on C++, > templates and the STL and say, "What in the hell were we thinking?!?". Some of us have been saying that for quite a while now =) -Hook |
From: <phi...@pl...> - 2003-01-06 20:42:19
|
"Grills, Jeff" <jg...@so...>: > GCC's code gen for this stuff is apparently a fair bit better. I had a brief look at this, with the view to potentially replacing some hand-rolled RTTI that had caused some minor bugs (the problem with hand-rolled RTTI is entirely one of maintenance). IIRC, my only gripe with GCC was that it kept the RTTI tables seperate from the vtables. Although I'm sure there's a good reason for this, it was going to add yet another potential cache miss, and so out it went. I don't think I even looked at the dynamic_cast code, as I was just going to be comparing types. Although I'm now tempted to turn it on in debug builds, to assert the hand-rolled RTTI is working. Cheers, Phil |
From: <ce...@ce...> - 2002-12-24 13:26:21
|
Hey, It might be a bad design, but now that I've hit this problem, I'd also like to know why it happens and how much RTTI would *really* hurt. The class hierarchy in discussion has a base Obect class that has a name field and is virtually inherited by all the other classes in the hierarchy. Now I have a Texture class and a RenderTarget class (buth abstract), and in the implementation I have a (say) D3DTexture class that inherits both Texture and RenderTarget. The problem is that the RenderSystem class (the one that does the actual rendering) is pretty abstracted itself so it works with Textures and renderTargets. At some point I have to cast from Object to D3DTexture and there's where all hell brakes loose. I can't even cast from void * to D3DTexture for that matter (well, the void * was initially a RenderTarget cast of D3DTexture, so yes, it is a whole madness). My bet is on dynamic_cast or modifying the design (I'll probably choose the latter eventually). Seems like hard abstraction would be way easier (and safer) with RTTI enabled. Thanks again, Adrian -----Original Message----- From: gam...@li... [mailto:gam...@li...] On Behalf Of Tom Forsyth Sent: Tuesday, December 24, 2002 3:02 PM To: gam...@li... Subject: RE: [GD-General] Overhead of RTTI It's usually far quicker and easier to code it yourself with a few helper functions, unless you actually need the full madness of RTTI. Tom Forsyth - Muckyfoot bloke and Microsoft MVP. This email is the product of your deranged imagination, and does not in any way imply existence of the author. > -----Original Message----- > From: Adrian Cearnau [mailto:ce...@ce...] > Sent: 24 December 2002 12:50 > To: gam...@li... > Subject: [GD-General] Overhead of RTTI > > > Hey everyone and merry X-Mas, > > I'd like to know what the realistic overhead of enabling RTTI in a C++ > project is. Any opinions are welcome. > > Thank you, > Adrian 'cearny' Cearnau ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ Gamedevlists-general mailing list Gam...@li... https://lists.sourceforge.net/lists/listinfo/gamedevlists-general Archives: http://sourceforge.net/mailarchive/forum.php?forum_id=557 |