I think you should use an immutable struct for your case. You have enough fields that it would be nice to have it an actual type. Named tuples are better for simple code. These can be immutable for the same reason the named tuple fields could be. You modify the existing arrays, rather than assigning a new one. Make a constructor that creates empty values of the right sizes.
A few idiomatic points.
- What you are talking about here is some sort of inplace solutions on a preallocated structure. So maybe name your type accordingly.
- by convention, you add the
!to the inplace solution function at the end, not the beginning. - by convention you make the mutated argument the first one, so I would call it
results = ResultTyoe(???) # do you need sizes?
# then in loop, etc....
innerfunc!(results, args)
But… Make 100% sure this is all worth it. Preallocating and doing things inplace often doesn’t help until things get large, and can hurt performance otherwise.