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

Calldata versus memory copies

Read-only call input and writable working memory have different roles.

LET’S PICTURE IT

A sealed incoming form differs from a writable working copy on the desk.

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.

Identify the location in the type

A Solidity reference parameter may be in calldata or memory depending on its declaration and context. The location changes access and copying behavior.

Use calldata for suitable input reads

Calldata is read-only input for the current message call. Reading it directly can avoid constructing a full writable memory copy when the operation supports that approach.

Copy when writable data is needed

Moving a byte sequence into memory allocates working space and copies data. The destination uses memory layout, which is not simply the packed storage representation.

Measure actual operations

A calldata declaration is not a universal zero-cost promise. Hashing, external calls and other operations may still require particular memory ranges or explicit copying.

Inspect the layout

bytes calldata input // read-only input reference
bytes memory copy = input; // writable copied data

A fragment illustrating data locations; it is not a complete contract.

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

Can an operation freely overwrite the current call’s calldata?

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.