At 29:07 of the video here: Devcon

it is mentioned and written in the slide that dynamic arrays have pointer slot, length slot and elements after the length slot

However, when I debug the following on Remix:

function test3(string memory i, string memory j) public {}

I only get length slot and elements for both string inputs enter image description here

My question is, why there is no pointer slot for both strings ?

EDIT: The same TX has pointer slot in its calldata

1 Answer 1


ChatGPT answered my question:

Absolutely, your understanding is correct. Solidity's handling of data, especially strings, within calldata and memory follows an optimization strategy to minimize gas costs and optimize memory usage. When data, including strings, is passed into a Solidity function as part of the calldata, it's treated differently compared to how it's managed within the contract's memory.

Calldata: Data passed in calldata is read-only and is often used for function arguments or data received from external calls. In calldata, strings are stored with a pointer and length, similar to how they're represented externally. This representation requires a pointer slot in the calldata, which helps external entities understand the data's layout and retrieve the necessary information, including the string's length and location.

Memory: Solidity optimizes memory usage when copying data from calldata to the contract's memory. When copying strings or other data types from calldata to memory, Solidity generally only stores the length and the actual data content in memory without requiring a separate pointer slot. This optimization helps reduce gas costs by minimizing memory usage within the contract while still allowing efficient string manipulation and data handling within the contract's context.

This distinction in how data is stored and managed in calldata versus memory helps Solidity contracts efficiently interact with external data while optimizing gas costs and memory usage within the contract's execution environment.

Whenever string information goes outside of the contract, we need pointer slot but when we manipulate string inside the contract itself, we only need the length and data

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.