Suppose I have two structures `A`

and `B`

. When I instantiate `A`

it creates a bunch of arrays say `a`

, `b`

, and `c`

that every instance of `B`

needs to performe it’s calculations. Let `x`

and `y`

be instances of `B`

. Then to calculate `x+y`

the function `function (+)(x::B,y::B)`

needs the values of `a`

, `b`

, and `c`

. What is the most efficient way of getting these value accessed by `function (+)(x::B,y::B)`

?

It seems the best way it to introduce a custom function `plus(x::B, y::B, c::C)`

where `C`

contains `a, b, c`

needed for your calculation. You may also put `C`

within every `B`

and relly on the fact that it only stores a pointer and thus there are no redundant copies. In some scenarios it is possible to store additional common parameters within a type parameter, but since in your case `a`

, `b`

, `c`

are vectors that does not seem wise as the Julia would need to recompile all methods for different `C`

. Also it may be reasonable in your situation to use `C`

as a global denoted with `const`

.

Thank you. I think I will pass a structure containing all the arrays and other data of `A`

every time I instantiate an instance of `B`

. One of the arguments of the constructor of `B`

will be `A`

.