By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,227 Members | 1,241 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,227 IT Pros & Developers. It's quick & easy.

Tools to analyze memory usage within a program

P: n/a
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
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
Jul 22 '05 #2

P: n/a
Ian
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
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.