flâneur — a map of the web's best reading

The Lost Art of Structure Packing

catb.org · 6,155 words · saved by 2 readers

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