Memory reuse problem in for loop

The thing is that these lines are creating a new mutable vector at every iteration (on the right).

That can be solved using StaticArrays and doing

u = @SVector [red(...) green (...) blue (...)]

(Or sometimes just a tuple, depending on how you use it after, may suffice)

2 Likes