Tools for Analyzing C++ Class Code Generation?
Milo_Mindbender submits this query: "I've got a midsize Linux project which uses a lot of STL and other C++ template code. Even considering this, I end up with a lot bigger text (generated code) segment than expected. I know the information about the amount of code generated for each class is in the objdump, but prying it out by hand is a problem when you get five line long template invocations and hundreds of methods to wade through. Can anyone can recommend some tools that analyze binary or objdump output and summarize the amount of code generated for each class, including each unique template or STL class?"
Too bad that C++ templates have nothing to do with OOP, but rather procedural programming. And while they have lots of problems (like code bloat) they are also phenomenally powerful for certain things (generic data structures). Even if you write nothing about procedural code, you could benifet from templates.
A deep unwavering belief is a sure sign you're missing something...
Huh? What did you expect? Templates lead to bloat per definition. That's what they do: a lot of binary code is generated by a small amount of typing. If bloat becomes a problem: redesign.
I know the information about the amount of code generated for each class is in the objdump, but prying it out by hand is a problem when you get five line long template invocations and hundreds of methods to wade through. Can anyone can recommend some tools that analyze binary or objdump output and summarize the amount of code generated for each class, including each unique template or STL class?
I wish I did. But most likely, I think you are fucked. Without an understanding of the code, it's hard to debug template problems. Find out where the bloat is by analysing the source code, not the binary.
If you do not already have a copy of Large-Scale C++ Software Design by John Lakos, get it. I realize this isn't a tool per se, but he has a terrific section in chapter 10 on Using C++ Templates in Large Projects.
It is kinda ugly for what it does but it works. Only one instantiation of std::vector is made, it is void*. Putting the member function definitions in the header file ensures they will be inlined if necessary.
I think Scott Meyers came up with this tip first.