登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

中吴南顾惟一笑

成功法则就是那19个字

 
 
 

日志

 
 

Datatype Misalignment  

2010-06-12 16:56:03|  分类: R&D |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
Why is Alignment Important?

exceptions & crash
performance penalty

How to 'Align' everything?

In general, alignment errors can be avoided by following these rules:

  * Do not enable structure packing.
            The rule is don't mess with how the compiler lays out fields in a struct.  
            If you need to pack more data into less space, re-arrange the data so the compiler doesn't have to waste space on padding.
            The easiest way to do this is to always organize your fields according to size: largest to smallest.  
            For C++ this applies to classes and structs.      

  * Do not access a small-aligned address by using a recast pointer of larger alignment.
          The easiest way is to just not fool with the compiler/OS.  
          The compiler will automatically layout locals and parameters on properly aligned addresses.  
          The same goes for malloc, realloc, new, etc.  
          The problem arises when you allocate one thing, but then treat it like something else.
  评论这张
 
阅读(667)| 评论(0)

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018