NEWTON
Asked
5 months ago
129
views
0
Are there situations in which we prefer declaring variables as local
vs tempvar
?
I understand that both are used to avoid variables being revoked, curious to know if they are different in any way
Thread
This question was originally posted on StarkNet Discord
Newton
asked
5 months ago
0
Accepted answer
There's this forum post : https://community.starknet.io/t/when-should-i-use-tempvar-instead-of-local/1668/4 that gives some answers to this question. There's an interesting example where to quote it "replacing locals with tempvars decreases the memory usage by a LOT" Also note that local and tempvar will be removed in Cairo 1.0 : https://medium.com/starkware/cairo-1-0-aa96eefb19a0the memory reduction is 10x when using tempvar instead of local
the memory reduction is 10x when using tempvar instead of local
and also:
with alloc_locals;
you don't need to use local
anymore, just let
- my rule of thumb is always use let
unless there's a circumstance where I need to use tempvar
This answer was originally posted on StarkNet Discord
Newton
answered
5 months ago
Cairo: When do you use tempvar and when do you use local
Cairo: let vs tempvar what is the difference?
Immutable Memory in Cairo
Cairo Lang / StarkNet: What are Revoked references? What is alloc_locals?
What are the projects on starknet that plan to do the domain .stark?
What does it mean to declare a 'local' variable inside a 'let'?
Declaring Strings in Cairo
Does Cairo work in python3.10 venv? I can’t install python 3.9
What do you think about current StarkNet Alpha and future Beta? What will Beta mean? When should it be beta?
ApeWorX: Why do I need to fund a Starknet account before deploying it?
Deploying kakarot evm on starkEx
My ABIs will be same right? In UI I am assuming I wont have to make any changes
StarknetErrorCode.ENTRY_POINT_NOT_FOUND_IN_CONTRACT error in Cairo. Can anyone help?
why does keccak256 replace sha256 in warp?