Hello, I recently found out this:
julia> b = rand((1024,1024))
julia> sizeof(b)
8388608
julia> @time b += 2;
elapsed time: 0.007002567 seconds (8388704 bytes allocated)
which, with further investigation, I could verify that it is allocating a new array every time I do something like b += 2,
instead of modifying the original object b points to.
Is this an intended behavior, or better, is there a command to optimize such operations?
I tried @devec but it also seems to generate a new destination array. I could also write my own function,
but I suppose there are better ways to deal with this.
Code such as b ./= 2 is very common, and this introduces array duplication, increasing memory usage as well as
additional unneeded operations (the former crashed my machine a few hours ago).
Thanks.