On Thursday, June 12, 2014 1:15:52 PM UTC-4, [email protected] wrote:
>
> My reading of the documentation suggests that indeed the structs will be 
> laid out in consecutive memory locations provided the struct is declared 
> 'immutable'.  Is this correct?
>

Yes, an array of immutable types is laid out in memory just like a C array 
of structs.

An array of mutable types (or of abstract types, e.g. Array{Real}) is 
stored as an array of pointers.
 

> Are tuples stored via pointers or as consecutive structs?  The docs don't 
> seem to say.
>

Tuples are a special case, mainly used for returning multiple arguments 
from functions and for other temporary storage, and are highly optimized by 
the compiler.

Often tuples aren't laid out in memory as any kind of arrays.  The tuple 
members (at least if they are immutable) are often stored directly in local 
variables, can be passed on the stack, and may get compiled into individual 
registers.   Homogeneous tuples can also get stuffed into SIMD registers. 
 See https://github.com/JuliaLang/julia/pull/4042

However, I think that if you force Julia to carry around an explicit tuple 
in a way that can't be inlined, it is stored as an array of boxed values 
(see https://github.com/JuliaLang/julia/blob/master/src/julia.h#L74-L83).   
So, tuples aren't really an efficient way to store lots of persistent data. 

Reply via email to