0

Some context: iOS app development. Objective-C code in Xcode.

This one has been confounding me for hours:

I have a little struct I created:

struct EIVertex {
    GLKVector3      P;
    GLKVector3      N;
    GLKVector3      barycentric;
    GLKVector2      st;
};

GLKVector3 and GLKVector2 are types found in the GLKit framework.

Here is what is weird:

sizeof(GLKVector2) = 8
sizeof(GLKVector3) = 12
sizeof(EIVertex) = 48

The size for EIVertex is 48 but should be 44 (12 + 12 + 12 + 8 = 44).

Can someone please explain why there is this size disparity?

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
dugla
  • 12,774
  • 26
  • 88
  • 136
  • There might be padding in the memory layout. The padding is used to get the member's address correctly aligned to some boundaries. In this case most likely 32-bit boundaries. – woodleg.as Apr 10 '13 at 23:38

1 Answers1

2

Structures in C tend to be padded for data alignment. Check this page for more information. Also refer to the answer in this question.

Community
  • 1
  • 1
Jorge Israel Peña
  • 36,800
  • 16
  • 93
  • 123