KodeWarrior
KodeWarrior

Reputation: 3598

Size of memory aligned struct

struct Test
{
    int a;
    char b;
    int c;
} __attribute__((packed, aligned( 128 )))test;

sizeof( test ) returns 128 .

Why is the size not 9 ?

Is it that memory is rounded of to multiple of 128 ?

For example:

struct Test
{
 int b;
 char c;
} test;

sizeof( test ) returns 8 ( rounded of to multiple of 8 )

Upvotes: 1

Views: 385

Answers (1)

Paul R
Paul R

Reputation: 212969

If you were to create an array of struct Test then each element would need to be 128 byte aligned, therefore each instance of the struct needs to be padded to a multiple of 128 bytes to maintain this. Hence sizeof(struct Test) = 128.

Upvotes: 3

Related Questions