Member order alignment packing in structs

Do I have to care about in which order to put data members of a struct in order to get optimal memory alignment packing or does Julia optimize the order automatically?

AFAICT it doesn’t because

struct BIB
    z::UInt8
    x::UInt64
    y::UInt8
end
sizeof(BIB)

prints 24. If it did pack and reorder members into the order x,y,z it would print 16 on a 64-bit machine.

Generally, Julia mirrors the C layout, so the same principles apply.

(Also, it seems that you are asking a lot of questions which are answered in the documentation. This is not a problem, but simply reading through the manual (not the reference, the standard library docs, or the devdocs, just up to maybe Performance Tips from the Getting Started) may clarify a lot of things, then you can ask about the details).

1 Like

Ok, I’ll investigate a bit before asking.