Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 839
user2665887 Avatar asked Sep 03 '14 17:09

user2665887


1 Answers

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.

like image 167
reem Avatar answered Nov 08 '22 16:11

reem