116 - Storage Packing
Storage Layout Packing: For each state variable, a size in bytes is determined according to its type.
Multiple, contiguous items that need less than 32 bytes are packed into a single storage slot if possible, according to the following rules:
-
The first item in a storage slot is stored lower-order aligned
-
Value types use only as many bytes as are necessary to store them
-
If a value type does not fit the remaining part of a storage slot, it is stored in the next storage slot
- State Variables
- Type -> Size in Bytes
- Contiguous & Size Fits
- Same Storage Slot
- Contiguous & Not Fit
- Next Storage Slot
- First Item -> Lower-order Aligned
Storage, Stack Memory, Storage, and Flow Operations, Storage Layout, Storage Packing, Storage Layout & Ordering, [Storage Layout & Inheritance], Storage Layout for Mappings & Dynamic Arrays, State Variables, State Variables