Slashdot Mirror


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?"

10 of 48 comments (clear)

  1. This article should have been called by GigsVT · · Score: 3, Funny

    "Why you shouldn't use OOP for anything important."

    --
    I've had enough abrasive sigs. Kittens are cute and fuzzy.
    1. Re:This article should have been called by be-fan · · Score: 4, Informative

      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...
  2. Me Too! by kzadot · · Score: 4, Funny

    Our large corporation also has a project, a client has requested that we implement BubbleSort, QuickSort, ShellSort, and one other sort that we learnt in cl^H^H^H^H^H^H^H^H^H err, discussed in a business meeting. The err, client also requests a 1 page analysis comparing and contrasting the differences between the searches.

    Can code generation do this? It could really increase my chances of a good mar^H^H^H err profit yeah.

  3. Uhhh, perl or python? by ComputerSlicer23 · · Score: 3, Interesting
    Uhhh, use your favorite scripting language. Doing the demangle might be a bit tricky, but nm or obj dump should do either of those for you. Then just parse the class names.

    Use a map or a hash. Oh, and lastly, move all the code in headers out into the .cxx/.cpp file, your code will compile faster, and probably run nearly as fast, with the exception of a handful of performance critical classes (finding them is important).

    Kirby

  4. OpenC++ by angel'o'sphere · · Score: 4, Interesting

    Search at source forge for Open C++ or OpenCPP, not sure how it is written.

    That is a programmable source to source transformer for C++.

    It spits out one singel file of c++ for every compiled C++ unit, removing the includes, by expanding them into the output.

    That way yo can source level debug the processed c++ code, not exactly what you want but likely more powerfull in the long run anyway.

    Your request varies far to heavy from compiler to compiler.

    angel'o'sphere

    --
    Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
  5. John Lakos by sohp · · Score: 3, Informative

    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.

  6. Reducing template bloat by mattgreen · · Score: 5, Informative
    Enough uninformed comments already. Most STL code bloat can be controlled pretty easily. What you do is make a wrapper over an STL class. For example if you're using std::vector you'd make a Vector class:
    template<typename T>
    class Vector
    {
    public:
    //ctors as necessary
    Vector();

    T get(size_t i)
    {
    return static_cast<T>(vec[i]);
    }

    void insert(T item)
    {
    vec.push_back(static_cast<void*>(item));
    }

    pri vate:
    std::vector<void*> vec;
    };
    You may wish to provide the exact functionality of the container you're wrapping, or you may wish to change the semantics. It's up to you.

    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.
    1. Re:Reducing template bloat by saurik · · Score: 4, Interesting

      If your data type really can be static_cast'd to a void * then there's probably a much better solution to this problem in almost 90% of the cases: it's called a "better compiler". I don't know what compiler you are using, but Visual Studio .NET finds functions whose assembly code generated the same and merges them (or whatever you want to call it: links all usages to the same implementation) at link time.

      So if you have a vector of int * and a vector of long * and a vector of MyObject * and a vector of unsigned long they should all generate the same assembly code and you should only end up with a single set of these in your resulting binary.

  7. Re:STL: that bad? by bmac · · Score: 3, Interesting

    Yup, STL is *partly* responsible for C++ being mostly worthless, but let's not forget the other big nail in C++'s coffin: multiple-inheritance. The ol' diamond of death means compiler-determined (and not in any kind of spec, that I know of, tho I may be wrong) implementation, which is an auto-no-go in my book. Then again, I've *never* seen a practical reason to use multiple inheritance. Most books just use some assinine example like animals, mammals, and cows. WTF?! I use C because it's deterministic, and the implementation offers no surprises, except for bugs in the linked libs, of course :-)

    Even in C# (which I use for rad development as a transition to straight C + win32/bsd), the Hashtable collection is totally fscked. After a certain number of elements it just goes to the weeds. Totally ridiculous. Some of the bugs in the *$2000* .NET IDE are so absurd that you wonder if Micro$oft isn't try to screw developers from being able to write sophisticated programs at all.

    Oh well, crappy software means I still have an market :-)

    Peace & Blessings,
    bmac

  8. Yes, but... by Nicolay77 · · Score: 3, Insightful

    I've seen template bloat in a lot of places, but MI bloat?

    Just because something can be done in the language doesn't mean everybody just goes and uses it. You're right that MI is too prone to mistakes, and it can be replaced most of the time by java-like interfaces.

    I use C++ because is deterministic, can be used to really big proyects, when it runs is fast as hell (can be faster than C when using inline functions), and because I don't use every shitty feature of the language just because it's there. The right tool for the job can be a subset of C++.

    --
    We are Turing O-Machines. The Oracle is out there.