Rules for Storage Location in Solidity

Rules for Storage Location in Solidity

Rule No. 1

State variables are always stored in the storage data location.

Rule No. 2

Whenever a variable is declared as a function parameter, it is stored into the memory data location.

Rule No. 3

Whenever a variable is declared as a function parameter, it is stored into the memory data location. But now, we have two cases here :

  • Within a function, value type variables are stored in memory, whereas reference type variables are stored in storage by default.
  • Value type variables declared in a function cannot be overridden and cannot be stored at the storage location but reference type variables can be overridden.
  • Mappings are always declared at the storage location. This means that they cannot be declared within a function. We can't declare at memory level but we can refer local mapping to mapping declared as a state variable.

Rule No. 4

The arguments supplied by callers to function parameters are always stored in call data locations.

Rule No. 5

Whenever you assign a state variable to another state variable, even inside of functions, you create a new copy.

Rule No. 6

A new copy is made whenever a storage variable is assigned from another memory variable.

Rule No. 7

A new copy is always created when a memory variable is assigned from another state variable.

Rule No. 8

Memory variables assigned from another memory variable do not create copies for reference types. However, they do create copies for value types

Anisur Rahman

Sr. React Native (Lead) Eng. ?? 6 yrs ?? Message for Projects ?? RN Advanced Guide Book (1.8K+ ??) ?? Author → #NotJustDev ?? (42K+ Devs)

2 年

Great job bro

回复

要查看或添加评论,请登录

Mohammad Haseeb的更多文章

社区洞察

其他会员也浏览了