If I have a
struct that has another
struct as a field, is the latter always copied as a whole? Eg
struct Large a::Int b::Int c::Int end struct UsesLarge l::Large d::Int end l = Large(1,2,3) sizeof(l) # 24 u1 = UsesLarge(l, 4) sizeof(u1) # 32
I am asking because for a problem I am working on, several small objects
y only make sense in context of a larger one
X. Currently the calling convention of my functions is
dostuff(X, y) but it would be very natural to compose the
X into the
ys. However, I am worried about memory, because there are many
X is large.
I don’t know how to reason about size in this case. Can I keep my objects immutable (
struct) and yet share memory for the
Xs? Is there any way to ensure this? I found this in the devdocs but I don’t know enough to understand it.