2014年6月10日 星期二

composite data type – its alignment and size


* array

alignment - 等同於元素的alignment
size - 元素size * 元素個數
example:
int array[10];
alignment – 4bytes
size – 4 * 10 bytes

* aggregate (struct)

alignment - 元素中最大的alignment
size – alignment 的最小倍數,並且足以容納所有元素
example:
struct {
char c;
int i;
};
alignment – 4 bytes
size – 8 bytes

* union

alignment - 元素中最大的alignment
size – alignment 的最小倍數,並且足以容納最大size的元素。
union {
char c;
int i;
};
alignment – 4 bytes;
size -  4 bytes

沒有留言:

張貼留言