--> Juan Alcolea wrote to All <--
JA> I am working in a big project written in C++, and I want to
JA>carefully control the dynamically allocated/deallocated memory,
JA>since I am using a lot of dynamic structures, and I suspect I have
JA>a memory leak somewhere. What I want is to keep track of the
JA>quantity of allocated mem, and the quantity of deallocated one, so
JA>I can inspect these values while running my program.
JA>
JA> I suposse that the best approach to acomplish this is overloading
JA>the operators new and delete. But I have a problem here: I cannot
JA>call the "global" default new from inside my overloaded new, even
JA>using the scope (::) operator; every attempt to call the original
JA>new results in a annoying recursive call to may own overloaded new,
JA>so I can't actually allocate memory using this approach.
If you are overloading the global new operator, you won't be able to
get the 'original' global new. If you are overloading new in a class
you can get the global new with ::.
Go ahead and overload the global new/delete, but use malloc()/free()
inside the implementation. Remember that you have to overload both
forms plain and [].
To check for memory leaks, use the memory allocation checking code in
Snippets--mem.c. This gives you a substitution for malloc()/free()
that keeps track of allocated/freed blocks.
Cliff Rhodes
cliff.rhodes@juge.com
crhodes@flash.net
X CMPQwk 1.42 1692 X"The cautious seldom err." - Confucius
--- Maximus/2 3.01
---------------
* Origin: COMM Port OS/2 juge.com 204.89.247.1 (281) 980-9671 (1:106/2000)
|