I construct millions of objects with some particular associated data (essentially, a transition table). I’d like to avoid storing this data in each object (even if it’s an extra pointer), since I can assume it’s constant throughout a computation. I’d also rather avoid making it a global, since (1) it’s known at compile time so could lead to optimizations and (2) I was taught to avoid globals. Here is a stripped-down version of my structure:
using StaticArrays
struct Data{T,Junk} x::T end
where Junk
should hold my transition table. Now
julia> Data{Int,[1]}
ERROR: TypeError: in Type, in parameter, expected Type, got a value of type Vector{Int64}
while
julia> using StaticArrays
julia> Data{Int,SVector{1}([1])}
works fine. However,
julia> Data{Int,SVector{10000}(ones(10000))}
is unbelievably slow.
Is there some better way of doing what I want?