tracking memory allocations by class

M

Manuel Massing

Hi,

I was wondering if there is an easy way to keep track of all allocations
issued by instances of a specific class and its subclasses (i.e. keep track
of memory consumption of the class instances, including e.g. heap-allocated
member variables).

A global overloading of new / delete operators is out of question, because
I have to track memory consumption for a specific class, and also because
the base class implementation will be dynamically linked.

I had no luck overriding the member operator new either, because while it
is called to allocate the class instance itself, allocations within the
instance cannot be tracked that way. Maybe via a friend declaration?

Ideally, this should work as transparently as possible, i.e. no placement
operator new or other syntax differences.

Thanks for your input!

Manuel
 
M

Michiel Salters

Manuel Massing said:
Hi,

I was wondering if there is an easy way to keep track of all allocations
issued by instances of a specific class and its subclasses (i.e. keep track
of memory consumption of the class instances, including e.g. heap-allocated
member variables).

A global overloading of new / delete operators is out of question, because
I have to track memory consumption for a specific class, and also because
the base class implementation will be dynamically linked.

I had no luck overriding the member operator new either, because while it
is called to allocate the class instance itself, allocations within the
instance cannot be tracked that way. Maybe via a friend declaration?

No, not possible, and I think the question isn't even sensible.
What exactly is the set of allocations, anyway? How about memory
allocated by factory methods? The factory may have used a cache, or
a memory pool. If the first allocation caused the factory to
new[] a pool of 100 objects, and the next 99 allocatons just
used that pool, do you assign the memory all to the first factory
user? What about std::cout? It may allocate a buffer when first
used, and resize it dynamically when large strings are printed.
How are you going to track that?

Regards,
Michiel Salters
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top