S
Spur
Hi all,
I implemented a memory allocation/deallocation class that logs all
new/delete calls (overloaded) and remembers for each allocated
block where it was allocated from (using a macro that passes __FILE__
and __LINE__). On destruction, it reports all undeleted blocks
(memory leaks).
The class is implemented in a separate .h/.cpp pair, and should be
linked to
code when I want to use it (plus a #define should be set and the
header should be included).
It works nicely, except for one problem - global objects. There is
one global instance of the logging class in the .cpp file, and it
catches all memory leaks from inside main() just fine. It misbehaves
with global objects - reporting many false alarms.
I'm aware of the fact that the order of construction/destruction of
global objects (in different files) is not specified by the standard.
However, I still wonder whether it's possible to implement this
somehow portably ? Non-portably (after all, checking for memory leaks
on one platform should be enough, I think...) ?
If not, it would be another good reason to never use globals B-)
Thanks in advance
Eli
I implemented a memory allocation/deallocation class that logs all
new/delete calls (overloaded) and remembers for each allocated
block where it was allocated from (using a macro that passes __FILE__
and __LINE__). On destruction, it reports all undeleted blocks
(memory leaks).
The class is implemented in a separate .h/.cpp pair, and should be
linked to
code when I want to use it (plus a #define should be set and the
header should be included).
It works nicely, except for one problem - global objects. There is
one global instance of the logging class in the .cpp file, and it
catches all memory leaks from inside main() just fine. It misbehaves
with global objects - reporting many false alarms.
I'm aware of the fact that the order of construction/destruction of
global objects (in different files) is not specified by the standard.
However, I still wonder whether it's possible to implement this
somehow portably ? Non-portably (after all, checking for memory leaks
on one platform should be enough, I think...) ?
If not, it would be another good reason to never use globals B-)
Thanks in advance
Eli