Tools to analyze memory usage within a program

Discussion in 'C++' started by Dennis McCrohan, May 20, 2004.

  1. 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
    Dennis McCrohan, May 20, 2004
    #1
    1. Advertising

  2. Dennis McCrohan

    Petec Guest

    Dennis McCrohan wrote:
    > 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


    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
    Petec, May 21, 2004
    #2
    1. Advertising

  3. Dennis McCrohan

    Ian Guest

    Dennis McCrohan wrote:
    > 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!
    >

    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
    Ian, May 21, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. metfan
    Replies:
    2
    Views:
    4,824
    Robert Olofsson
    Oct 21, 2003
  2. PHP
    Replies:
    8
    Views:
    465
  3. dspfun

    Good ways to analyze a running c-program?

    dspfun, Dec 30, 2006, in forum: C Programming
    Replies:
    6
    Views:
    359
    progman
    Dec 31, 2006
  4. Replies:
    2
    Views:
    264
  5. hch
    Replies:
    0
    Views:
    238
Loading...

Share This Page