In this track: Storage, memory and layout
advanced · 4 MIN READ

Fixed array storage layout

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
Pack small values into Solidity storage slotsFirstuint128 A16 bytesSeconduint128 B16 bytesThirduint256 C32 bytesSimple elementary types only; not a complete compiler layoutSlot 0 · 32 bytesUnused · 16 BA · 16 BHigh-order bytes ← → low-order bytesSlot 0 · fullB · 16 BA · 16 BDeclaration order and sizes determine this packingSlot 0BASlot 1C · 32 bytesTry different sequences in the storage-layout tool

In this simple default-layout example, two uint128 values come before one uint256. Each slot holds thirty-two bytes.

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.

Inspect the layout

uint128[3] items; // slots 0 and 1
uint8 flag;      // slot 2

The fixed count is part of the type, not an extra count word.

TURN UNDERSTANDING INTO PRACTICEOpen the Storage layout →
QUICK CHECK · NO PRESSURE

How many slots does uint128[3] occupy?

Your progress stays in this browser.
Keep exploring the original referenceSolidity documentation ↗

Original explanations by EtherTools. Examples are educational and source-linked; this site is independent of the Ethereum Foundation. Our approach.