Four data structures for storing variables in Ethereum smart contracts

1. storage

Global variables in the contract that can be accessed by all functions. Storage is permanent storage, which means that Ethereum will store it on every node in the public chain environment.

The contract state variables will be permanently saved, and the fuel consumption is the largest.

2. Memory

The life cycle of the memory variables in the contract is from the beginning of the contract to the end of execution, and is destroyed after execution.

Only temporary variables are saved and released after the function is called, which consumes very little fuel.

3. Calldata

The data of all function calls, including the storage location of function parameters. Is an unmodifiable memory location.

It contains the data of the message body, and its calculation needs to increase the gas cost of n * 68 (n is the number of non-zero bytes in calldata)

4. Stack

EVM maintains a stack in order to import variables and the machine/assembly instruction code of Ethereum. This stack is the memory work space of EVM. It has a depth of 1024 levels, that is, if you store more than 1024 levels of data, an exception will be triggered.

The stack saves only small local variables, free trial, the number is limited to 16 variables.

Reference: Ethereum solidity smart contract development

Guess you like

Origin blog.csdn.net/weixin_41787421/article/details/109282976