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.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容