通过对齐查找C结构中的孔 [英] Find holes in C structs due to alignment

查看:76
本文介绍了通过对齐查找C结构中的孔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在gcc或clang(或任何其他编译器)中是否有办法吐出有关结构中是否有孔(内存对齐)的信息?

谢谢.

ps:如果还有另一种方法,请告知我.

解决方案

您可以使用 pahole 输出有关结构中孔的信息,并有选择地尝试对它们进行填充.

您可能想阅读玩个坑和朋友们" pahole公告以获取更多信息

Is there a way in gcc or clang (or any other compiler) to spit information about whether a struct has holes (memory alignment - wise) in it ?

Thank you.

ps: If there is another way to do it, please do inform me.

解决方案

You can use pahole to output information about holes in structures and optionally attempt packing them.

You may want to read "Poke-a-hole and friends" and the pahole announcement for more information

这篇关于通过对齐查找C结构中的孔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆