База знаний / Видео

Class layout, Miloš Anđelkovic

This is a talk about how the non static member variables are laid out in memory. Part that is not covered is the case with virtual inheritance as it complicates things and this should only take an hour.
We start out with the Standard layout type, what it is, why it exists and what are it's requirements.
Then the exploration of the language rules how the different blocks of variables with the same access can be moved around and how that was changed in C23.
Next the inheritance and how it impacts the layout of the class with the mention of empty base class optimization. As a pair to inheritance the same (similar example) using composition (member variables) and no_unique_address attribute. This followed with examples using the clangs -cc1 - fdump-record-layouts which will generate reports for the layouts of the classes. As part of this mention the Subobjects.
Alignment requirements of the operating system and C
and padding. Brief mention of alignof and alignas operators and many align_ functions in C++, but just a mention as there will be no time for details.
Finally a simple benchmark showing difference in performance between the structs that have the same member variables but one has a «good» and the other «bad» layout.