20,000 USDC
View results
Submission Details
Severity: gas
Valid

Using storage instead of memory for structs/arrays saves gas

Summary Using storage instead of memory for structs and arrays can save gas in certain scenarios. Let's discuss how and when this gas optimization can be beneficial.

When you declare a struct or an array in Solidity, you have the option to define it in either storage or memory. Here are the key differences:

1-Storage: When a struct or an array is declared in storage, its data is stored permanently on the blockchain. It is assigned a storage slot and can persist across multiple function calls and transactions.

2-Memory: When a struct or an array is declared in memory, its data is temporary and exists only during the execution of a function. It is not stored on the blockchain and is discarded after the function call completes.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.