Specifying size of vector in a struct

I have a struct like so:

struct rpoint
    pn::Int64 #patch number
    xyz::Vector{Float64} #coordinates

Note: the xyz field will always be populated with a vector of size 3. I have two questions:

  1. Is it true that not specifying the size of the vector can lead to sub-par performance? When I profiled my code, I got a bunch of red “runtime-dispatch” flags, which I’m trying to track down. Can the above cause it?
  2. How would I specify the size of the vector in the struct?
  1. Does not seem likely to be the cause.
  2. Switch from Vector to a type from the StaticArrays package.

Yes, but here you may be confusing with not specifying the dimensions of an Array, which is what would give you run time dispatch problems (type instability in general). It likely that your red flags come from something else.

Here the standard and best option is to use SVector from the StaticArrays package.

1 Like