Compile-time vs run-time polymorphism with C++

  Рет қаралды 3,611

constref

constref

3 жыл бұрын

In this video we go over runtime, virtual function based polymorphism, and then we look at how we can achieve polymorphic code using compile-time methods while avoiding any performance penalties due to virtual function dispatch.
The method presented here may be helpful when trying to optimize a game/engine main-loop, avoiding indirection due to virtual calls.

Пікірлер: 20
@Fleshbits1
@Fleshbits1
I wish people would quantify the "performance penalty" When talking about virtual methods for the last 3 decades. It's the same cost as adding 1+1, no? Or de-referencing a pointer. Are we scared to add 1+1 and talk about performance every time we do? Even in embedded or game programming, I don't know why people are so scared of dynamic polymorphism. ... and as far as I know you HAVE to have dynamic polymorphism in order to mock in your unit tests. You at minimum need to use an interface and have a concrete class. Maybe I'm wrong, but noone has ever shown me otherwise. I'd love to learn if I am wrong.
@nhanNguyen-wo8fy
@nhanNguyen-wo8fy
why don't you upload the code, people have a hard time moving back and fort to read your code.
@priyanshu_hiro
@priyanshu_hiro 3 жыл бұрын
Super awesome/useful stuff. A lot of things became clear to me.
@goldsphere48
@goldsphere48
What if you do this? Let's say in the engine we only use the renderer interface - the header file, that is, essentially pointers to functions. And for each backend we implement it in dll. Thus, when starting the application, we decide which dll needs to be loaded, and if we want to use another one, we can ask to restart the application. This is how we solve the problem of virtual functions. We do not solve the problem of the minimum application size, but for example, for mobile platforms we can supply only one dll that will be used there. And we do not load all dlls into RAM, just one. What do you think about this?
@sheldonfernandes3588
@sheldonfernandes3588 2 жыл бұрын
Thank YOU!! :D
@Fleshbits1
@Fleshbits1
In your example of changing out the renderer via template argument, how does one even know T is actually a renderer? it could be a fat melting factory for all we know, no?
@tutorialstube9587
@tutorialstube9587 2 жыл бұрын
Your emacs looks cool. Can you please have a video regarding for how to configure emacs for C++ development? thanks
@saltwaterx5100
@saltwaterx5100 Жыл бұрын
If there's a problem, just add another level of indirection. Classic.
@ali51717
@ali51717 3 жыл бұрын
Definitely Useful for me,
@nhanNguyen-wo8fy
@nhanNguyen-wo8fy
8:53
@jeremyed9507
@jeremyed9507
Why does Renderer need to inherit from App? Wondering if it would be best to overload the
@klaik30
@klaik30
This video makes zero sense to me. Your alternate solution has just built another layer on top of the application. You haven't added or changed any lower layers which is actually calling the RENDER function, which was our purpose for having it virtual in the first place.
Debugging C/C++ with LLDB Tutorial
40:06
constref
Рет қаралды 24 М.
Alex hid in the closet #shorts
00:14
Mihdens
Рет қаралды 17 МЛН
Викторина от МАМЫ 🆘 | WICSUR #shorts
00:58
Бискас
Рет қаралды 4,9 МЛН
Macros in C++
19:36
The Cherno
Рет қаралды 234 М.
C++ Polymorphism and Virtual Member Functions [6]
12:13
Professor Hank Stalica
Рет қаралды 10 М.
Why The Windows Phone Failed
24:08
Apple Explained
Рет қаралды 184 М.
If Your Code Looks Like This... You're A GOOD Programmer
16:39
Continuous Delivery
Рет қаралды 37 М.
20 Advanced Coding Tips For Big Unity Projects
22:23
Tesseract
Рет қаралды 171 М.
Alex hid in the closet #shorts
00:14
Mihdens
Рет қаралды 17 МЛН