Hmm, I don't think this is completely fair. It's a bit hard to tell because the slides aren't there, but when people say "virtual functions are slow", they don't usually mean "virtual functions are slower than function pointers". Sometimes, you *need* runtime polymorphism, and virtual functions are good then (though reducing virtual calls is still good). But often, you can make a choice between runtime polymorphism and static polymorphism (e.g templates), and runtime polymorphism is usually the slower option there.
@babgab Жыл бұрын
Someone should let Casey Muratori know :D
@thelatestartosrs Жыл бұрын
I think the argument is more about if you have chains of virtual functions which can be avoided if you only compute the type once through your std::variant usage.
@sparker2426 Жыл бұрын
If a switch statement is as slow as a virtual function call then the compiler isn't doing its job.
@higaski Жыл бұрын
Just because you can doesn't mean you should. Are you going to rewire the Arduino during runtime? Most likely no, then why pay for any overhead at all? Hardware simply isn't virtual.