# Member order alignment packing in structs

**URL:** <https://discourse.julialang.org/t/member-order-alignment-packing-in-structs/14232>\
**Category:** General Usage\
**Created:** [August 29, 2018, 9:42am UTC](https://discourse.julialang.org/t/member-order-alignment-packing-in-structs/14232 "2018-08-29T09:42:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nordlow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nordlow/32/4970_2.png) [@nordlow](https://discourse.julialang.org/u/nordlow)\
**Post date:** [August 29, 2018, 9:42am UTC](https://discourse.julialang.org/t/member-order-alignment-packing-in-structs/14232/1 "2018-08-29T09:42:38Z")

</div>

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

```julia
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.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 29, 2018, 10:24am UTC](https://discourse.julialang.org/t/member-order-alignment-packing-in-structs/14232/2 "2018-08-29T10:24:21Z")

</div>

Generally, Julia [mirrors the C layout](https://docs.julialang.org/en/stable/manual/calling-c-and-fortran-code/#Struct-Type-correspondences-1), 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).

---

<div class="post-metadata">

**Author:** ![nordlow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nordlow/32/4970_2.png) [@nordlow](https://discourse.julialang.org/u/nordlow)\
**Post date:** [August 29, 2018, 12:15pm UTC](https://discourse.julialang.org/t/member-order-alignment-packing-in-structs/14232/3 "2018-08-29T12:15:25Z")

</div>

Ok, I’ll investigate a bit before asking.
