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

Memory expansion basics

Accessing farther memory can increase execution cost.

LET’S PICTURE IT

A worktable can be extended when a task reaches beyond its current usable area.

SEE IT FOR YOURSELF
Use temporary memory in one execution frameStep 1 / 4
Use temporary memory in one execution framePointer wordmemory address 0x40value: 0x80Working areabegins at 0x80not a storage slotCompiler memory conventions differ from persistent storage layoutValue 42hex: 0x2aleft-padded in a wordMSTOREoffset 0x80bytes 0x80–0x9fA retained manual allocation must also maintain the memory pointerMLOADoffset 0x80read 32 bytesStack result42same stored wordMLOAD and SLOAD access different data locationsRETURN rangeoffset 0x80size 32 bytesOutput bytesencoded integer 42caller interprets schemaEach message-call frame has its own memory working space

This frame uses temporary byte-addressed memory. Solidity normally keeps a free memory pointer at address 0x40, initially pointing to 0x80.

Animated local teaching model. No wallet, RPC or live blockchain data. Some labels and hashes are abbreviated for readability.

Separate memory from storage

EVM memory is temporary byte-addressed working space for an execution frame. It is not persistent contract storage and does not use Solidity’s storage packing layout.

Track the highest accessed range

An operation touching farther memory can expand the active memory region. Both the starting offset and the accessed size matter when deciding the new boundary.

Understand cumulative cost

Expansion cost depends on the new memory size and includes a quadratic component. Splitting expansion into several steps does not remove the cumulative expansion component for the same final size.

Avoid unbounded copies

A large user-influenced copy or allocation can consume substantial gas. Bound the work according to the application and test large inputs rather than assuming memory is free.

Inspect the layout

MSTORE at offset 0x80 writes bytes 0x80 through 0x9f.
Memory expansion depends on the accessed range, not merely the starting byte.

This memory example uses byte addresses, not storage slot indices.

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

Is EVM memory persistent across separate transactions?

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.