News for hackers. Stuff that matters.
Re:Under the hood of C++ lambdas and std::function by mike_hock on Monday March 28, 2016 @09:38AM (#11374153)
The only virtual call that you necessarily get with polymorphism is the destructor call.

Whenever you need to make a function virtual in C++, you'd need to store a function pointer in an equivalent C design, somehow.

Re:Under the hood of C++ lambdas and std::function by hellofunk on Monday March 28, 2016 @11:17AM (#11374751)
Are you suggesting that C++ virtual functions have the same overhead as a C function pointer? I've never heard that; with the virtual call, there is the lookup + the invocation; perhaps a C app that stores function pointers in a hash map also has this sort of lookup, is that what you mean?
Re:Under the hood of C++ lambdas and std::function by mikeash on Monday March 28, 2016 @11:57AM (#11374997)
Vtable lookup in a typical C++ implementation is just loading a fixed offset in an array. In C terms, it's basically doing object->vtable[42]. In C code with function pointers, you're typically performing that exact same operation. You can go slightly faster if you store the function pointer in the object directly, at the cost of increased memory consumption per object if you have more than one function pointer.