Some think about the data alignment

zhaozj2021-02-16  89

Some thinks about data alignment:

See INFOROC's article.

Here is the test results on Solaris8: the combined sizeof value is the maximum data type in the joint;

The SIZEOF value of the structure is an integer multiple of the maximum data type size in the structure. The principle of alignment is that the data item can only be stored at the address of the integer multiple of the data item size. Therefore, the complementary part is added to the variable that is closest to the big data item.

For example:

Union {

Char a;

INT B;

Float C;

Double D;

} utest;

SizeOf (Utest) = 8; // SizeOf value is the size of the maximum data type in the joint.

Struct {

Char a;

INT B;

Double C;

Char D;

Char e;

Char f;

Char g;

Char H;

Int J;

STEST;

SizeOf (STEST) = 32; // Estably occurring 3 bytes after A; h behind 3 bytes; J 4 bytes later.

转载请注明原文地址:https://www.9cbs.com/read-15250.html

New Post(0)