Difference between release and debug build when initial a struct

本文探讨了在调试和发布构建中初始化结构体时出现的冗余字节填充差异问题。在调试构建中,冗余字节被填充为0xcc;而在发布构建中,则被填充为0x00。文章提供了两种解决方案:一是使用#pragmapack(1)进行内存布局调整;二是调用ZeroMemory()函数来显式清除内存。

Today meet such a bug, when initial a struct with a redundant bytes, using struct a = {0}; the release build and debug build acts differently!

In the debug build, the redundant bytes are filled with 0xcc, while in the release build the redundant bytes are filled with 0x00.

Solution:

1 Use #pragma pack(1) .  it’s better way, with more capacity, and efficiency.

2 call ZeroMemory().

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值