java 字节对齐_字节对齐详解(Byte alignment).doc

字节对齐详解(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

Http:///jszj/archive/2009/02/20/3915328.aspx

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 various data types on 32 machines is as fo

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值