Are the entries in a vector of immutable structs stored in place, or
is there always a pointer to the heap?
(Or how can I get Julia to do something equivalent).
I have a question about the interplay between vectors and
mutable/immutable structs.
If I have a vector of mutable structs, then obviously then each entry
in the vector has an independent life in the heap (since the same
object could be in more than one vector, and if I modify a struct
stored in one vector I can see the modifications in another vector).
On the other hand, if I have a vector of immutable structs (of
well-defined size), then there is no need for a pointer to an
independent object - I can store the contents of the struct in situ. There is no need for independent allocation on the heap.
The question is: does Julia do this, or is there some way to get the
same effect, so that when I push structured but immutable data onto a
vector, it is written into the vector in the same way as if I were to
push an integer onto a vector of integers, and not linked via a
pointer.
Motivation is obviously to avoid allocating heap storage every time I
push a structured something onto a vector.
Wait. What changed in 1.4? I thought that efficient arrays of small unions was a thing dating from Julia 0.7 (eg. the whole missing efficiency thing). Did the storage strategy change?
My understanding was that the struct is still stored inline for non-isbits types, but the contents of the struct may be pointers.Update: this is wrong, see below.
I don’t think so because you would then have to recreate the Julia object holding those structs on getindex. So either the data is stored inline, or you have pointers to structs.