> Mauro, I do not quite understand what you're saying about densely packed 
> arrays, could you explain a bit more?

Consider:

julia> immutable A
       x::Float64
       y::Float64
       end

julia> type B
       x::Float64
       y::Float64
       end

julia> a = [A(4,5), A(5,6)]
2-element Array{A,1}:
 A(4.0,5.0)
 A(5.0,6.0)

julia> b = [B(4,5), B(5,6)]
2-element Array{B,1}:
 B(4.0,5.0)
 B(5.0,6.0)

Then in memory `a` is actually identical to:

[4., 5., 5., 6.]

(or
[4. 5.; 5. 6.]  )

As Julia knows that the type of `a` is Vector{A}, it knows how to
interpret that junk of memory.  Conversely, `b` is a vector of pointers
which point to the two instances of `B`.  So, working with b is slower
than an Array{Float64,2} whereas a should be just as fast.

> Thanks,
> Chris
>
> On Tuesday, March 3, 2015 at 11:41:53 AM UTC-5, Mauro wrote:
>>
>> > I believe if all your type fields are concrete (which they are in the 
>> case 
>> > of Float64), the performance should be the same as using 
>> Vector{Float64}. 
>> > This is really nice since you get to use code that is much more 
>> > understandable like state.x instead of state[1] for no penalty. 
>>
>> I think to get densely packed array the type needs to be immutable: 
>>
>> immutable StateVec 
>>     x::Float64 
>>     y::Float64 
>>     z::Float64 
>> end 
>>
>> Otherwise it will be an array of pointers. 
>>

Reply via email to