Mutable struct vs Ref in an immutable one?

The const annotation requires Julia 1.8. Which one to use is depend on how you want to use them. For struct A the access y[] will almost always require a pointer dereference. B has a nicer layout in memory and the compiler can load both x and y simultaneously.

A downside is the layout when the A and B are contained in other structures. As an example inside an array A can be stored inline whereas for B a reference will be stored.

5 Likes