The Lost Art of Structure Packing
This page is about a technique for reducing the memory footprint of programs in compiled languages with C-like structures - manually repacking these declarations for reduced size. To read it, you will require basic knowledge of the C programming language. You need to know this technique if you intend to write code for memory-constrained embedded systems, or operating-system kernels. It is useful if you are working with application data sets so large that your programs routinely hit memory limits. It is good to know in any application where you really, really care about optimizing your use of memory bandwidth and minimizing cache-line misses. Finally, knowing this technique is a gateway to other esoteric C topics. You are not an advanced C programmer until you have grasped these rules. You are not a master of C until you could have written this document yourself and can criticize it intelligently. This document originated with "C" in the title, but almost everything in it applies to C++
The Lost Art of Structure Packing The Lost Art of Structure Packing Eric S. Raymond < esr@thyrsus.com > Table of Contents 1. Who should read this 2. Why I wrote it 3. Alignment requirements 4. Padding 5. Structure alignment and padding 6. Bitfields 7. Structure reordering 8. Awkward scalar cases 9. Readability and cache locality 10. Other packing techniques 11. Overriding alignment rules 12. Tools 13. Proof and exceptional cases 14. Other languages 14.1. C++ 14.2. Go 14.3. Rust 14.4. Java 14.5. Swift 14.6. C# 15. Supporting this work 16. Related Reading 17. Version history 1. Who should read t
Explore this link on the map →saved by
related reading
- C++ Memory alignment - should we care? - Stack Overflowstackoverflow.com
- Struct padding in C++ - Stack Overflowstackoverflow.com
- Who ordered memory fences on an x86? | Bartosz Milewski's Programming Cafebartoszmilewski.com
- abseil / Performance Hintsabseil.io
- Optimization of Computer Programs in Cicps.u-strasbg.fr
- how I think when I think about programming - alice mazalicemaz.com
- Data representation – CS 61cs61.seas.harvard.edu
- Rust Optimization.md · GitHubgist.github.com
- Nobody ever got fired for using a structfeldera.com
- Static search trees: 40x faster than binary search · CuriousCodingcuriouscoding.nl
- Type-Safe and Portable Support for Packed Data (Experience Paper)drops.dagstuhl.de
- Adrian Sampson: Flattening ASTs (and Other Compiler Data Structures)cs.cornell.edu