Kartlee
Kartlee

Reputation: 1179

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 alignment of structures so I can avoid compiler-generated padding?

Upvotes: 5

Views: 4187

Answers (2)

DipSwitch
DipSwitch

Reputation: 5638

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...

Upvotes: 1

ninjalj
ninjalj

Reputation: 43748

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.

Upvotes: 3

Related Questions