체인의정석

Solidity constants vs immutable 차이 본문

블록체인/Solidity

Solidity constants vs immutable 차이

체인의정석 2022. 7. 6. 14:30
728x90
반응형

https://ethereum.stackexchange.com/questions/82259/what-is-the-difference-between-the-constant-and-immutable-keywords-in-solidity

 

What is the difference between the constant and immutable keywords in Solidity?

What is the difference between the constant and immutable keywords in Solidity and how do I use them?

ethereum.stackexchange.com

a) For a constant variable, the expression assigned to it is copied to all the places where it is accessed and also re-evaluated each time. This allows for local optimizations.

b) Immutable variables are evaluated once at construction time and their value is copied to all the places in the code where they are accessed. For these values, 32 bytes are reserved.

 

둘다 처음 constructor에서 한번 정의되면 다시는 변경되지 않는 변수로서 작용하는 공통점이 있다.

 

하지만 constant의 경우 불러질때 사용되지만 매번 다시 검사가 되며, 

immutable의 경우 다시 검사가 되는 것이 아니라 32 바이트가 reserved 되어 가져와서 사용한다는 차이점이 있다.

728x90
반응형
Comments