Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / General Programming / RTTI concrete asm implementation Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
Pogacha

April 27, 2005, 05:26 PM

When I active RTTI and use dinamic cast in a minor number of the total classes of a big program, using VC6, how the compilator implements an RTTI dinamic cast?
Iīm not worry about memory usage, I read that only adds a pointer to each instance, but I realy need to know if its faster or slower than a hand maked switch of the posibles clases to determine the type casting.
Thanks!

 
Nils Pipenbrinck

April 28, 2005, 05:58 PM

1. code a test-case.
2. enable assembler output
3. compile
4. load assembler output into editor
5. read assembler output

 
Fabian 'ryg' Giesen

April 28, 2005, 07:12 PM

Don't know how exactly the VC6 versions works, but all dynamic_cast implementations I've seen so far are rather slow and require a lot of pointer chasing.

A good reference is http://www.codesourcery.com/cxx-abi/ - the C++ ABI (Application Binary Interface) for Itanium, which is also being adopted for x86 by many compiler vendors (for example it is the de-facto standard under Linux).

In the "sample code" section there's a link to the implementation of dynamic_cast as used in GCC (only the part under "#else" "// new abi" is relevant). As the data structures used are completely specified in the ABI document, other implementations are bound to look very similar.

In essence, this is a lot of ugly code that will get executed and most certainly not inlined. So a switch will most probably be faster, as long as we're only talking a few different types here.

However, that kind of switch Statements is awful, maintenance-wise, and when you're doing ANY kind of dynamic type-based dispatching in performance critical code you should really REALLY think about your design. OTOH, if this is not performnace critical code, you shouldn't be worrying about that kind of stuff at all.

 
Pogacha

April 29, 2005, 06:54 AM



Nils Pipenbrinck wrote: 1. code a test-case. 2. enable assembler output 3. compile 4. load assembler output into editor 5. read assembler output


I can do that if we were talking about straight code, but here I got memory allocation displacement and data structures that I really donīt know.

Thanks anyway.

 
Pogacha

April 29, 2005, 07:14 AM

Thanks, I didnīt find the answer in that link, I get a little dizzy instead, but all the people tell me that do not use it. I still doubt about it so Iīll experiment width similar code to see what hapens.
Implementations for GCC and VC6 are not the same, in GCC the code grows when you activate the rtti, and in VC6 only when you use it.
I think that a dinamic_cast could be implemented using a matrix of the transitive inherit, but I really dont know cos it could be a huge memory trap (n^2 class number), Off-course the compiler could separate into banks of unconected classes and point to this structures, and in this way it must be faster than a switch, but got to repeat I donīt know, thats the reason of my doubt.
Thanks again.

 
Chad Austin

April 29, 2005, 07:29 AM

Maybe you'll find some info in the Technical Report on C++ Performance: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1666.pdf

 
Fabian 'ryg' Giesen

April 29, 2005, 10:59 AM

Off-course the compiler could separate into banks of unconected classes and point to this structures, and in this way it must be faster than a switch


A big table that's bound to be out of cache most of the time vs. a small jump table? Don't think so.

 
Pogacha

April 29, 2005, 05:10 PM

Thanks, Im reading now.

 
Pogacha

May 06, 2005, 04:05 PM

Right, the paper tells that dynamic cast is slower no matther what you do, its not good for critical time, but for using in downcast its situable for most aplications, the main cost is in the inherit-level, crosscast get double cost (alway talking about time).
Thanks again! that paper is gold.

 
This thread contains 9 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.