How has CPU architecture evolution affected virtual function call performance?

AMD processor in the early-gigahertz era had a 40 cycle penalty every time you called a function Huh.. so large.. There is an “Indirect branch prediction” method, which helps to predict virtual function jump, IF there was the same indirect jump some time ago. There is still a penalty for first and mispredicted virt. function … Read more

Can you cache a virtual function lookup in C++?

There are two costs to a virtual function call: The vtable lookup and the function call. The vtable lookup is already taken care of by the hardware. Modern CPUs (assuming you’re not working on a very simple embedded CPU) will predict the address of the virtual function in their branch predictor and speculatively execute it … Read more

C++ header file and function declaration ending in “= 0”

This is a pure virtual function. This means, that subclasses have to implement this function, otherwise they are abstract, meaning you cannot create objects of that class. class ISomeInterface { public: virtual std::string ToString( ) = 0; } class SomeInterfaceImpl : public ISomeInterface { public: virtual std::string ToString( ) { return “SomeInterfaceImpl”; } } The … Read more

Ways to detect whether a C++ virtual function has been redefined in a derived class

You can’t check for override of virtual function portably. You need to bring the knowledge to the Solver, preferably via type as opposed to run-time flag. One (type-based) way is to check for presence or absence of a interface, via dynamic_cast. A probably better way is to provide overloads of solve function, in your case … Read more

What if I don’t heed the warning “hides inherited member. To make the current member override that implementation….”

It will not do anything but the method you have there F() is also not polymorphic. It becomes very easy to make mistake in code if you started to use base class reference hence you are warned. Of course it can be what you want, hence the new keyword just make it more explicit E.g. … Read more

Avoiding the overhead of C# virtual calls

You can cause the JIT to devirtualize your interface calls by using a struct with a constrained generic. public SomeObject<TMathFunction> where TMathFunction: struct, IMathFunction { private readonly TMathFunction mathFunction_; public double SomeWork(double input, double step) { var f = mathFunction_.Calculate(input); var dv = mathFunction_.Derivate(input); return f – (dv * step); } } // … var … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)