(was: delete() confusion)
I have a class with multiple base classes. One of these base classes
(base1) has its own new/delete operators and nothing else. Another base
class (base 2) has a virtual destructor. The class with the virtual
destructor has AddRef() and Release() methods, and Release() ultimately does
a "delete this". Can that "delete this" statement somehow find the right
delete method? If it does, it involves a downcast and an upcast to get to
the right place.
Beyond this, I am having a fit trying to figure out, I guess, "delete
visibility" for polymorphic objects. Delete is always static, so it seems
that the class actually being "deleted" needs to have the class with the
correct delete method as a base class. But what if you wind up with
multiple base classes with their own delete operators?
[I have inherited code with a BUNCH of rocket science assembler level memory
management put together by a system architect who got his PhD in memory
strategies. He's gone, and now the new builds are not stable. My first
choice was to comment out ALL new/delete operators and just use the heap,
but the system won't stay in real time under load. I think the memory
management stuff works, but the C++ interface to it -- new and delete -- is
not safe. He was a memory and architect guru but maybe not a C++ guru. I
am no kind of guru, but I'm here on a saturday 2 weeks behind a release
schedule sweating bullets. HELP!!]
I have a class with multiple base classes. One of these base classes
(base1) has its own new/delete operators and nothing else. Another base
class (base 2) has a virtual destructor. The class with the virtual
destructor has AddRef() and Release() methods, and Release() ultimately does
a "delete this". Can that "delete this" statement somehow find the right
delete method? If it does, it involves a downcast and an upcast to get to
the right place.
Beyond this, I am having a fit trying to figure out, I guess, "delete
visibility" for polymorphic objects. Delete is always static, so it seems
that the class actually being "deleted" needs to have the class with the
correct delete method as a base class. But what if you wind up with
multiple base classes with their own delete operators?
[I have inherited code with a BUNCH of rocket science assembler level memory
management put together by a system architect who got his PhD in memory
strategies. He's gone, and now the new builds are not stable. My first
choice was to comment out ALL new/delete operators and just use the heap,
but the system won't stay in real time under load. I think the memory
management stuff works, but the C++ interface to it -- new and delete -- is
not safe. He was a memory and architect guru but maybe not a C++ guru. I
am no kind of guru, but I'm here on a saturday 2 weeks behind a release
schedule sweating bullets. HELP!!]
Comment