Inline Polymorphism!?

Started by
13 comments, last by Matt Calabrese 22 years ago
I tried this out last night on CodeWarrior 7.0. When I made the call on an object, like in your example, it was resolved statically. The call was made without using the vtable in debug mode, and inlined in release mode.

Other than that the vtable was always used. It was even used when I made an object, took a reference to it of the same type as the object and made a call on the reference.
Advertisement
quote:Original post by Matt Calabrese
Would the call to "Poo" be made inline?

The code in question can be entirely resolved statically. Therefore, the question of whether the function is inlined depends on the same rules that determine whether a function will be inlined when non-virtual. In your example, I would say the inlining issue is irrelevant, as the compiler should perform an empty method optimisation.

[edited by - SabreMan on March 20, 2002 7:04:34 AM]
Sabreman, that was just an example. Just "pretend" there was stuff between the brackets.

--------------------
Matthew Calabrese
Realtime 3D Orchestra:
Programmer, Composer,
and 3D Artist/Animator
"I can see the music..."
Actually, I did assume that''s what you meant. The sentence:

"the question of whether the function is inlined depends on the same rules that determine whether a function will be inlined when non-virtual"

covers that scenario. I added the sentence about your actual example as a side-note. I guess your selective reading filter must have kicked-in.
quote:Original post by Krunk
I tried this out last night on CodeWarrior 7.0. When I made the call on an object, like in your example, it was resolved statically. The call was made without using the vtable in debug mode, and inlined in release mode.

Other than that the vtable was always used. It was even used when I made an object, took a reference to it of the same type as the object and made a call on the reference.



This is intended behaviour. Virtual methods should only incur a vtable overhead penatly when used polymorphically (ie with base class pointers).

This topic is closed to new replies.

Advertisement