Small array elements can pack within their reserved region.
LET’S PICTURE IT
A tray has a known number of equally sized compartments.
SEE IT FOR YOURSELF
Pack small values into Solidity storage slotsStep 1 / 4
In this simple default-layout example, two uint128 values come before one uint256. Each slot holds thirty-two bytes.
In this simple default-layout example, two uint128 values come before one uint256. Each slot holds thirty-two bytes.The first sixteen-byte value occupies the low-order half of slot zero. Low-order bytes are shown on the right.The second uint128 fits in the remaining sixteen bytes. Both values now share slot zero.C needs a complete thirty-two-byte slot, so it begins at slot one. Two packed small values plus C use two slots.
Animated local teaching model. No wallet, RPC or live blockchain data. Some labels and hashes are abbreviated for readability.
Use the fixed count
A uint128[3] array has a count supplied by its type. It does not store a separate dynamic-array length word in its base slot.
Pack within each slot
Two sixteen-byte elements fit in its first slot. The third element begins at lower-order offset zero in the next slot.
Do not split an element
Packing places whole suitable elements within a word. It does not break one elementary array element across the end of a storage slot.
Reserve the following boundary
A state variable after the array starts in a fresh slot. The unused upper half of the final array word is not reused by that variable.