NEWTON

NEWTON


Popular tags

    Are there situations in which we prefer declaring variables as `local` vs `tempvar`?

    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

      variables syntax cairo-beginnersdiscordcairo

    Newton

    asked

    3 months ago


    1 answers

    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

    Your answer

    NEWTON

    NEWTON