开发者

Optimization tools for C and C++

What tools for Windows and Linux systems can I use to determine alignment issues, cache misses and other parameters relevant to code generated by Visual C++ and GCC? Can I use these tools to determine the alignme开发者_开发知识库nt of structures so I can avoid compiler-generated padding?


To determine cache misses you'll want a CPU-level profiler, like oprofile or vtune, or a dynamic instrumentation tool, like valgrind with cachegrind.

To look for alignment issues on structures, there is a tool called pahole for object files with DWARF debugging information.


If you want to avoid padding in data structures you could using __attribute__((__packed__)) for gcc or for microsoft visual studio #pragma(pack(push,1)) before the declaration of your structure an #pragma(pop) after the declaration of your structure. You could also give the command line option to microsoft visual studio compiler /Zp1 for packing at one byte http://msdn.microsoft.com/en-us/library/xh3e3fd0(v=vs.80).aspx or with gcc -falign-function=8 for packing at 1 byte boundaries. Your code base would be smaller however this could have serious negative effects on your performance...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜