Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Virtual calls themselves are more time consuming than normal calls because it has to lookup the address of the actual function to call from the vtable </p> <p>Additionally compiler optimizations like inlining might be hard to perform due to the lookup requirement. Situations where inlining is not possible itself can lead to quite a high overhead due to stack pop and push and jump operations</p> <p>Here is a proper study which says the overhead can be as high as 50% <a href="http://www.cs.ucsb.edu/~urs/oocsb/papers/oopsla96.pdf" rel="nofollow noreferrer">http://www.cs.ucsb.edu/~urs/oocsb/papers/oopsla96.pdf</a></p> <p>Here is another resource that looks at a side effect of having a large library of virtual classes <a href="http://keycorner.org/pub/text/doc/kde-slow.txt" rel="nofollow noreferrer">http://keycorner.org/pub/text/doc/kde-slow.txt</a></p> <p>The dispatching of the virtual calls with multiple inheritances is compiler specific, so the implementation will also have an effect in this case. </p> <p>Regarding your specific question of having a large no of base classes, usually the memory layout of a class object would have the vtbl ptrs for all the other constituent classes within it. </p> <p>Check this page for a sample vtable layout - <a href="http://www.codesourcery.com/public/cxx-abi/cxx-vtable-ex.html" rel="nofollow noreferrer">http://www.codesourcery.com/public/cxx-abi/cxx-vtable-ex.html</a></p> <p>So a call to a method implemented by a class deeper into the heierarchy would still only be a single indirection and not multiple indirections as you seem to think. The call does not have to navigate from class to class to finally find the exact function to call. </p> <p>However if you are using composition instead of inheritance each pointer call would be a virtual call and that overhead would be present and if within that virtual call if that class uses more compositio,n more virtual calls would be made. That kindof a design would be slower depending on the amount of calls you made. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload