字节对齐详解(Byte alignment)
字节对齐详解(Byte alignment)
Byte alignment detail - jack-wang - C++ blog
Jack-wang
C++ blog home new essays contact polymerization management
Essays, -107 reviews, -17 articles, -0, trackbacks-0
Byte alignment
I. what is byte alignment and why should it be aligned?
The memory space of modern computer are in accordance with the byte classification, in theory seems to be of any type of variable access can start from any address, but the actual situation is when accessing a specific type variables often in
Fixed memory address access, which requires various types of data to be arranged in space in accordance with certain rules, rather than sequential emissions one after another, which is alignment.
The role and reason of alignment: each hardware platform is very different from the processing of storage space. Some platforms can access certain types of data only from certain addresses. For example, some of the schema's CPU is in access
When a variable is not aligned after an error, so in this
framework must be byte aligned. Other programming platform is likely not the case, but the most common is the platform for if not in accordance with the requirements of
Data storage alignment results in loss of access efficiency. Some platforms, for example, start reading from my address at any time, if a int (assuming 32 bit system) is stored at the beginning of my address
A read cycle can read the 32bit, and if stored at the start of the odd address, 2 read cycles are needed, and the number of bits and bytes of the two read results are pieced together to obtain the 32bit number
According to the. Obviously, the reading efficiency has dropped a lot.
Two. Byte alignment affects the program:
Let's look at some examples first (32bit, x86 environment, gcc compiler):
Set the structure as follows:
Struct A
{
Int a;
Char b;
Short c;
};
Struct B
{
Char b;
Int a;
Short c;
};
It is now known that the length of v
字节对齐详解Bytealignment 来自淘豆网m.daumloan.com转载请标明出处.