This depends entirely on context. If this code appears in a gobal scope (or
in the REPL) then each return value will be separately heap allocated. If
the code occurs in the middle of a function and the variables are all local
and Julia's compiler can infer the type of x, then x will be stored in
registers or on the stack. The easiest way to tell is by looking at the
output of @code_typewarn for type instabilities and @code_llvm/native for
lots of reading/writing of memory.

On Sun, May 15, 2016 at 5:35 AM, Kristoffer Carlsson <[email protected]>
wrote:

> Since these are just normal integers they will (assuming you are putting
> them in a function) be allocated on the stack so no gc will need to run.
>
> If x instead allocated something then the previous x would still be in
> memory until the gc desides to clean them up. I'm not sure about the exact
> question but frequent unnecessary allocations can significantly affect
> performance, yes.
>
>
> On Sunday, May 15, 2016 at 9:55:39 AM UTC+2, Ford Ox wrote:
>>
>> Just from pure curiosity.
>>
>> x = 10
>> x = 100
>> x = x << 2
>> x = foo() # returns int64
>>
>> Will x after any of these instruction use new memory storage (thus there
>> will be two x variables present, until gc deletes the one with no pointer)?
>> If yes, does it affect performance significantly?
>>
>>

Reply via email to