Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to make storage references

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

How to make storage reference, in response to this problem, this article details the corresponding analysis and solution, hoping to help more small partners who want to solve this problem find a simpler and easier way.

Storage introduced

The storage property is a reference type. In the following contract, a dynamic length array arrx is defined, and arrx is a variable stored in the storage space of the Ethereum virtual machine.

When the test method is called, the variable uint[] Z is defined. At this point, if we compile in the remix browser, we will see a warning. Because by default, for dynamic arrays

The storage attribute is added. That is: uint[] storage x. A storage attribute is a reference type that references a state variable in the Ethereum VM storage space. rather than copies of values.

Therefore, in the test function, after modifying the length and content of Z, look at the length and content of arrx again and you will find that the correspondence has changed.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

pragma solidity ^0.4.23;

contract storageStart{

uint[] public arrx=[1,2,3,4,5];

function test() public{

uint[] Z = arrx;

Z[0] = 100;

Z.length = 10;

}

function getLength() public view returns(uint){

return arrx.length;

}

}

About how to carry out storage reference questions to share the answer here, I hope the above content can be of some help to everyone, if you still have a lot of doubts not solved, you can pay attention to the industry information channel to learn more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report