If found an example which challenges my understanding of what allocations are or are not. If
one creates a vector of tuples of different lengths, it is possible to mutate the smaller ones into larger ones without allocating memory:
julia> v = [ isodd(i) ? (0,0) : (0,0,0) for i in 1:1_000_000 ];
julia> function mutate_vec!(v)
for i in 1:length(v)
v[i] = (1,1,1)
end
end
mutate_vec! (generic function with 1 method)
julia> @btime mutate_vec!($v)
371.502 μs (0 allocations: 0 bytes)
julia> v[1]
(1, 1, 1)
julia> v[2]
(1, 1, 1)
julia>
What does that mean? If that is possible, what is not??
All tuples are and continue to be on the stack? When one mutates a tuple for another tuple of the same size, it does not remain at the same place in the stack? Is the complete pile of tuples moved - a new one created and the older one discarded - on the stack?