visual studio 字节对齐 pack应用

32位的电脑内存一般都是4 bytes对齐。

struct _ONE_BYTE_STRUCT{

char m_byte;

};

struct _ONE_BYTE_STRUCT 结构体对象占用内存 4byte;


visual studio IDE 编程使用 关键字。修改内存对齐字节数

#pragma pack(1)

//定义的结构体 1字节对齐

......//去掉内存 4 字节对齐,对结构体内存控制起到关键作用

#pragma pack(4)

//定义的结构体 4字节对齐


#pragma pack()详见MSDN说明:

#pragma pack( [ n] )

Specifies packing alignment for structure and union members. Whereas the packing alignment of structures and unions is set for an entire translation unit by the /Zp option, the packing alignment is set at the data-declaration level by the pack pragma. The pragma takes effect at the first structure or union declaration after the pragma is seen; the pragma has no effect on definitions.

When you use #pragma pack(n), where n is 1, 2, 4, 8, or 16, each structure member after the first is stored on the smaller member type or n-byte boundaries. If you use #pragma pack without an argument, structure members are packed to the value specified by /Zp. The default /Zp packing size is /Zp8.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值