Article View: comp.std.c++
Article #2985Re: RTTI implementation...
From: Steve Clamage
Date: Fri, 05 Jan 1996 21:20
Date: Fri, 05 Jan 1996 21:20
54 lines
2923 bytes
2923 bytes
In article 2e1@trojan.neta.com, jonnyg@trojan.neta.com (J. Greenblatt) writes: >Problem: > It seems that RTTI requires a compile time flag to be activated. When >activated the code seems to bloat whether you actualy use the feature in the >specific peice of code or not. From what I have learned this overhead is due >to extra work done when the object is constructed (A pointer to this with a >string representation of the class is added to a table). That sounds like not a very efficient way to implement RTTI. I would expect all RTTI extensions to consist only of static data, with a pointer to such static data in the vtable for a type. Vtables are also normally static data. (Types with no virtual functions don't have RTTI available anyway, except for built-in types.) The only RTTI overhead is the extra static data tables, one table per RTTI type. Objects should have no space or time overhead whatever associated with RTTI. (We are talking about implementation details here, not language definition. Certainly RTTI implementations exist that work the way I have described.) >Proposed solution: > Allow RTTI to be implemented on the whole system as it is now and keep >it as a option. In addition allow RTTI to be turned on on a class by class >basis. On a class by class basis RTTI would be enabled if a base of the >current class is declared with the RTTI keyword. The extra RTTI keywords >(dynamic_cast, static_cast, etc...) are only defined for classes declared >as RTTI classes. The RTTI overhead is now only felt when accessing objects >of RTTI classes. But every class would have to be declared to be RTTI or they wouldn't be very useful. A major purpose of classes is to serve as a base for further development. If you create a FOO class and put it in library, no client of the class could use RTTI on derived classs unless you make FOO an RTTI class. A C++ implementor might choose to have a compiler flag that eliminated the RTTI data to reduce static data space in programs that don't want to use RTTI, just as some compilers have a flag that turns off exception code. That isn't, and IMHO should not be, part of the language definition. Compilers operating in a no-exception or no-RTTI mode are not truly C++ compilers. The ability to disable such language features is there for those with severe space constraints. --- Steve Clamage, stephen.clamage@eng.sun.com -- Matt Austern SGI: MTI Compilers Group austern@isolde.mti.sgi.com
Technical Details
Message-ID:
<4ck3cv$qts@engnews1.Eng.Sun.COM>Path:
arc1-ca.pugleaf.net!chronicle.mti.sgi.com!newsReferences:
<4ciauq$2e1@trojan.neta.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!news From: clamage@Eng.Sun.COM (Steve Clamage) Newsgroups: comp.std.c++ Subject: Re: RTTI implementation... Date: 05 Jan 1996 21:20:04 GMT Organization: Sun Microsystems Inc. Approved: austern@mti.sgi.com Message-ID: <4ck3cv$qts@engnews1.Eng.Sun.COM> References: <4ciauq$2e1@trojan.neta.com> Reply-To: clamage@Eng.Sun.COM NNTP-Posting-Host: isolde.mti.sgi.com