Version 1.2

: Packing Structs

Optimizing Memory Layout of C++ Data Structures


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.


Day: 2015-07-25
Start time: 16:25
Duration: 00:30
Track: Main Talk (30min)




Click here to let us know how you liked this event.