NEWTON
Asked
3 months ago
125
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
3 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
3 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
How to fix `bud_ptr`
How to generate a proof for a Cairo program and verify it?[StackOverflow]
anyone know how to disconnect the connected wallet on the frontend with starknetjs or another way?
What are the projects on starknet that plan to do the domain .stark?
How do I transform data from javascript to Cairo?
Abi.encode and Abi.decode in Cairo?
Can you explain about cancellation (L1 -> L2) in StarkNet (sequencer)?