To summarize the advantages of type+immutable:
- convenience of a nice accessors (e.g a.x)
- less overhead
(The timings were run in a loop and mb and time were added up)
* 0.0036441109999999725s 2mb -> a = [1,2,3,4] # this is actually a lot 
better, than the last time i benchmarked this :)
* 0.0010228019999999729s 1mb -> a = Vec4(1,2,3,4) + immutable
* 0.0012369930000000022s 1mb -> a = Vec4(1,2,3,4) + type
- you can dispatch on the length, so you can specialize code for different 
vectors (e.g. Vec3,Vec4)
- at least for me, Vector{Vector3} is nicer to handle than Matrix(Float64)
For immutables only:
you can get arrays which are tightly packed and have the same layout like a 
vector in C, which is nice for compatibility and speed.

To get these advantages, you can use ImmutableArrays  
<https://github.com/twadleigh/ImmutableArrays.jl>or my more generic 
FixedSizeArray 
<https://github.com/SimonDanisch/FixedSizeArrays.jl>prototype.
The prototype is not ready yet, but should be soon. If you're interested, 
you are more than welcome to contribute!



Am Dienstag, 3. März 2015 16:00:21 UTC+1 schrieb Chris:
>
> Hello,
>
> Most of my Julia code basically involves dynamics simulations, and thus 
> state vectors. So far, I have simply been using ::Vector{Float64} as the 
> type for my state vectors, but I have seen other Julia code that defines a 
> composite type for this, something like:
>
> type StateVec
>     x::Float64
>     y::Float64
>     z::Float64
> end
>
> My question is (hopefully) simple: what benefit, if any, does this give 
> over simply using Vector{Float64}? If it is not quite obvious by now, I 
> am a Matlab transplant, and this is one of those things I haven't quite 
> been able to wrap my head around yet.
>
> Thanks,
> Chris
>

Reply via email to