Effective replacement of dynamic polymorphism with std::variant - Mateusz Pusz [ACCU 2019]

preview_player
Показать описание
#C++ #ACCUconf

This short talk presents how easy it is to replace some cases of dynamic polymorphism with std::variant. During the lecture, we will analyze and compare a few implementations of the same simple Finite State Machine. It turns up that variant-based code is not only much faster but also it gives us the opportunity to define our interfaces and program flow much better. The talk will end up with the discussion of pros and cons of each approach and will try to give guidelines on when to use them.

-------------------

Software architect, chief engineer, and security champion with more than 14 years of experience in designing, writing and maintaining C++ code for fun and living. C++ consultant, trainer, and evangelist focused on Modern C++. His main areas of interest and expertise are code performance, low latency, stability, and security.

Mateusz worked at Intel for 13 years and now he leads C++ Community at EPAM Systems. He is also a founder of Train IT that provides C++ trainings to corporations. Mateusz is an active voting member of the ISO C++ Committee (WG21) where, together with the best C++ experts in the world, he shapes the next official version of the C++ language. He is also a member of WG21 Study Group 14 (SG14) responsible for driving performance and low latency subjects in the Committee. In 2013 Mateusz won “Bench Games 2013” – worldwide competition in the C++ language knowledge.

-------------------------
Future Conferences:
ACCU 2019 Autumn Conference, Belfast (UK):
2019-11-11 and 2019-11-12.
ACCU 2020 Spring Conference, Bristol (UK), Marriott City Centre:
2020-03-24 to 2020-03-28.
-------------------------
ACCU Twitter: @ACCUConf

Рекомендации по теме
Комментарии
Автор

Due to the huge volume of footage/material related to these talk videos we are unable to review each video in its entirety. We try our best to catch any errors, mistakes or issues with the videos prior to their release online, but sometimes they do slip through. If you notice an error with this video, or you feel any part of it is not up to scratch, please inform us by leaving a comment and we will do our very best to correct the issue and upload a new version as soon as possible.

We also welcome any feedback related to the videos. If you think there's something we can do better, or perhaps just differently, then please do let us know so that we can adapt our processes for future videos.

ACCUConf
Автор

This is a great talk. I've come back to it several times.

However, it's not true that inheritance "forces dynamic memory allocation." As noted in C++ Core Guideline C.10, "the use of indirection is fundamental for run-time polymorphic interfaces. The allocation/deallocation overhead is not." You can allocate objects wherever you want, and still have dynamic dispatch through a pointer.

drplat
Автор

Isn't storing variables inside state variants dangerous? 14:07 Because the same memory will be reused for different states, so when the state changes, the old bytes can be overwritten, no?

Astfresser
Автор

Good talk, thanks! Is there a chance to have a look at slides somewhere?

Krzysztow
Автор

Code from ~11:50 does not compile (CRTP example).