Tools to analyze memory usage within a program

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dennis McCrohan

    Tools to analyze memory usage within a program

    Hi-

    I'm wondering if anyone has run across any program for C++ development
    that will help track the memory usage of different objects (class
    instances) within a program. I find it's easy enough on various
    platforms to get a handle on the total memory usage of your program for
    different testcases. But what I'm interested in is finding out where the
    memory usage is going within the program (sort of like how profiling
    tools tell you the function/line number where your run-time is going). A
    hierarchical report listing each class, the number of instances created
    of that class, and the same info for each sub-class would be ideal. I've
    generated this kind of info on a limited basis in the past simply by
    adding instrumentation to the destructors of classes. But now I'm
    dealing with a s/w system that is large enough I don't look forward to
    doing that by hand!

    Thanks,

    -dm


  • Petec

    #2
    Re: Tools to analyze memory usage within a program

    Dennis McCrohan wrote:[color=blue]
    > Hi-
    >
    > I'm wondering if anyone has run across any program for C++ development
    > that will help track the memory usage of different objects (class
    > instances) within a program. I find it's easy enough on various
    > platforms to get a handle on the total memory usage of your program
    > for different testcases. But what I'm interested in is finding out
    > where the memory usage is going within the program (sort of like how
    > profiling tools tell you the function/line number where your run-time
    > is going). A hierarchical report listing each class, the number of
    > instances created of that class, and the same info for each sub-class
    > would be ideal. I've generated this kind of info on a limited basis
    > in the past simply by adding instrumentation to the destructors of
    > classes. But now I'm dealing with a s/w system that is large enough I
    > don't look forward to doing that by hand!
    >
    > Thanks,
    >
    > -dm[/color]

    In standard C++ (the topic of this group) I believe the only way to do so is
    to do something like this:

    class C
    {
    static size_t count;
    public:

    C() { ++count; }
    C(const C&) { ++count; }
    ~C() { --count; }

    static size_t BytesUsed() { return sizeof(C) * count; }
    };

    For development tools, please ask on a group for your platform.

    - Pete


    Comment

    • Ian

      #3
      Re: Tools to analyze memory usage within a program

      Dennis McCrohan wrote:[color=blue]
      > Hi-
      >
      > I'm wondering if anyone has run across any program for C++ development
      > that will help track the memory usage of different objects (class
      > instances) within a program. I find it's easy enough on various
      > platforms to get a handle on the total memory usage of your program for
      > different testcases. But what I'm interested in is finding out where the
      > memory usage is going within the program (sort of like how profiling
      > tools tell you the function/line number where your run-time is going). A
      > hierarchical report listing each class, the number of instances created
      > of that class, and the same info for each sub-class would be ideal. I've
      > generated this kind of info on a limited basis in the past simply by
      > adding instrumentation to the destructors of classes. But now I'm
      > dealing with a s/w system that is large enough I don't look forward to
      > doing that by hand!
      >[/color]
      This stuff, while useful, is non-standard and tool specific.

      Your tool chain may or may not support this, search for it in your
      documentation.

      You could write your own allocator and call it through macros passing in
      file and line info. I did this once and it worked well.

      Ian

      Comment

      Working...