Grouping Base Types

This section looks at ways to achieve optimizations in grouped C/C++ types. The way in which grouped types are created has an impact on the footprint as well as the performance of the type.

Structs

The use of structures as data containers seems pretty straightforward, which it is really, when you take one or two things into account before using structures for large sets of data. Listing 6.9 demonstrates several ways of creating a grouped type.

Code Listing 6.9. Structure Sizes
 // Structure Size example #include <iostream.h> struct A { char a; long b; char c; long d; } ; struct B { char a; char c; long b; long d; } ; #pragma pack(push,1) struct C { char a; long b; char c; long d; } ; #pragma pack(pop) void main(void) { cout ...

Get C++ Footprint and Performance Optimization now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.