memory storage calldata
memory 存储在EVM内存中,主要有局部变量,函数参数,值传递
storage 存储在区块链中,主要有状态变量,复杂变量,数组,引用传递,指针
calldata,用来存储函数参数,是只读的,不会永久存储的一个数据位置。外部函数的参数(不包括返回参数)被强制指定为calldata。效果与memory差不多,但更为节约gas。
int[] arr;
string tt;
function fun1(uint m, string memory s) public returns(string memory) {
uint n = m;
string memory str = s;
tt = s;
string memory s1 = 'abc';
string memory s2 = s1;
int[] storage abc = arr;
return tt;
}
function fun2(uint m, string calldata s) external {
uint n = m;
string memory str = s;
}