I have couple of questions ( maybe dumb :-) ) regarding composite types:

1) For a vector of composite type defined as:

immutable Point{T<:AbstractFloat}
  vstate   :: Vector{T} # is a vector of length 6 which will be updated 
during code execution
  ct       :: Vector{T} # is a vector of length 4 which will be updated 
during code execution
  id       :: Int64 # is a constant input
end
N = 1000
MyPoints = Array(Point,N)

is it more useful / recommended to use immutable or mutable composite types 
? I am mainly concerned with memory allocation and performance while 
accessing MyPoints.

2) If we have a immutable composite type as:
immutable Body{T}
  μ      :: T
end

immutable PRB{T} #constant, doesn't change once set
    bodlist     :: Vector{T} #vector of another immutable type
end
b = Body(1.0)
prb = PRB([b])

and we access the variables as follows, results in memory allocation:

@time b.μ

  0.000002 seconds (5 allocations: 176 bytes)

@time prb.bodlist[1].μ

  0.000004 seconds (6 allocations: 192 bytes)

why is there a memory allocation every-time I access these variables ? 
(both for nested and the un-nested case)

thanks for all the help,
Nitin

Reply via email to