dynamic_cast
i was just wondering what exactly gose on under the hood when you use a dynamic cast? I know that it is a way to get the compiler to accept a child class in place of a parent class but i heard its pretty slow so what exactly goes on?
thanks[smile]
The short answer is "a hell of a lot".
The long answer is, of course, implementation dependent, but usually involves following the pointer into the vtable and indexing a type information block of some sort. The type information block may contain a tree or list of valid conversions and the pointer patch ups necessary to use them, including the indexing rules to access virtual bases properly. This usually results in a number of string comparisons.
You might be able to follow the disassembly in the your compiler to get a better idea of what happens.
The long answer is, of course, implementation dependent, but usually involves following the pointer into the vtable and indexing a type information block of some sort. The type information block may contain a tree or list of valid conversions and the pointer patch ups necessary to use them, including the indexing rules to access virtual bases properly. This usually results in a number of string comparisons.
You might be able to follow the disassembly in the your compiler to get a better idea of what happens.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement