Solidity之memory

问题来源与Solidity常见问题之What is the memory key word
以太坊虚拟机有三种areas可以来存放items.

  • 第一个就是storage 所有的contract的状态变量都放在这 每个contract都有自己的storage区域 在function调用之间是都可见的 用起来有点贵
  • 第二个就是memory 这个是用来存放临时变量的 在function调用之间是不可见的 也就是说一个function调用完了之后就会被erased 用起来比较便宜(开销小)
  • 第三个就是stack 用来存放small local variables 小的局部变量 用起来几乎免费(开销这么小的?)但是只能hold住有限量的变量(can only hold limited amount of values)

For almost all types, you cannot specify where they should be stored, because they are copied everytime they are used.

The types where the so-called storage location is important are structs and arrays. If you e.g. pass such variables in function calls, their data is not copied if it can stay in memory or stay in storage. This means that you can modify their content in the called function and these modifications will still be visible in the caller.

你可能感兴趣的:(Solidity之memory)