What is the memory layout of structs, tuples and tuple structs?
Asked Answered
M

1

9

It is clear from the reference manual that the memory layout of structs is unspecified (when the repr attribute is not used). This rule gives the compiler the possibility to pack structures tighter by reordering the fields.

What about the memory layout of tuples and tuple structs? How is it (un)specified and why?

Mills answered 3/9, 2014 at 17:15 Comment(0)
F
6

The memory layout of tuples and tuple structs is undefined, just like the layout of normal structs, with one exception:

The exception to this is the unit tuple (()) which is guaranteed as a zero-sized type to have a size of 0 and an alignment of 1.

The compiler can make the same optimizations in tuples and tuple structs that it can in structs, it just has to re-order matches of them as well.

Flacon answered 10/9, 2014 at 22:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.