Volker Kause - Packing Structs: Optimizing Memory Layout of C++ Data Structures - Akademy 2015
Channel: The KDE Community
Date: 2016-04-02

When reducing memory usage we first tend to look at allocating less instances of our classes, but once we reach the limits of that investigating and optimizing the memory layout of our data structures becomes interesting.

The way a C++ compiler puts data fields of an object into memory is based on a number of simple rules. However, the consequences of these are not always apparent when reading or writing C++ code, and even seemingly trivial changes such as reordering member variables can have an impact on the size of the entire object.

In this talk we will look at how the member variables of a C++ class are placed in memory and how to introspect the layout of such data structures. We will also look at easy ways on how to avoid wasteful padding, as well as more advanced approaches to achieve an even more compact memory layout.

These kind of optimizations are generally interesting for anyone dealing with classes with many instances, and thus especially for library developers who need to prepare their code for a wide range of (possibly unexpected) use-cases. 

Speaker: Volker Krause
License: Creative Commons Attribution 4.0 International License http://creativecommons.org/licenses/by/4.0/
Akademy 2015: https://akademy.kde.org/2015
KDE: https://www.kde.org/
Donate: https://www.kde.org/donate