I can’t remember where I saw this, but somewhere I read that dynamic polymorphism does not allow the compiler to make various optimizations.
Also, can anyone deepen me with any examples of such “missed” optimization opportunities that polymorphism prevents the compiler from creating?
FROM
Derived d; d.vMethod(); // that will call Derived::vMethod statically (allowing inlining).
C (if only one of Derivedor is Derived::vMethoddeclared finalin C ++ 11):
Derived
Derived::vMethod
final
void foo(Derived& d) { d.vMethod(); // this will call virtually vMethod (disallowing inlining). }
A virtual call has an additional cost (as an indirectness via vtable).
++ 11 final, .
, ++ . , List. ..
Poly.vmethod() , vmethod() , Poly- > vmethod() - . (, , . .)
(RVO) - , . RVO : , "" . .
Source: https://habr.com/ru/post/1526258/More articles:How to control login flow in ADAL AuthenticationContext? - azureПочему (возможно) плохая идея обрабатывать данные базы данных с такими языками программирования, как C/Python? - sqlPDFBox - PageDrawer draws outside PdfPagePanel - javaGet the weekday number of a month from a specific date on VBA - dateCan the resolver automatically format case statements on a single line? - resharperразрешать данные базы данных с помощью ui-route - angularjsHTML5 and Schema.org, why use both? - html5Can a terminal operation (e.g. forEach) recheck exceptions? - javaHow to rename a field during serialization using Json4s? - jsonWhy are ReSharper and the built-in MSTest runner ignoring my tests, which should not be ignored? - unit-testingAll Articles