473,765 Members | 2,070 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

delete, polymorphism, and multiple inheritence

(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!!]

Jul 19 '05 #1
2 5406
Ian McBride wrote:
(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.
I don't know. It worked ten minutes ago... What does VC++ have to say
about the listing I posted?
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?
Then you should put a using directive in the derived class for the base
class operator delete you want to use, or else provide a new operator
delete in the derived class that does the right thing.
[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!!]


Good luck.
Buster.

Jul 19 '05 #2
On Sat, 19 Jul 2003 13:14:03 -0400, "Ian McBride" <ia************ @yahoo.com> wrote:
(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?
Yes. In the statement "delete p;", if p is of static type T*, and if T
has a virtual destructor, and if the object pointed to is of type D derived
from T, then the D destructor must be invoked first of all, which implies a
dynamic downcast. From there the destructor action moves up the class
hierarchy, until finally (all destructors executed) the memory is
deallocated using "T::operato r delete".

§12.5/4 describes the detailed rules for which "operator delete" is called.

Now this implies that even though "operator delete" is a static function
it's accessed via some mechanism resembling a virtual method call, i.e.
in a C++ implementation that uses the vtable mechanism, via the vtable.
If it does, it involves a downcast and an upcast to get to
the right place.
The base class parts of an object are not allocated separately from
the object. The object including all its base class parts is allocated
in one chunk. If the object is of type T then "T::operato r new" is used
for allocation, and, if it has a virtual destructor, "T::operato r delete"
for deallocation.
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'm not 100% sure whether that is allowed, although I do think so, but
it does seem like a recipe for disaster. Presumably there's some reason
for these operators being defined. So instead of inheritance consider
encapsulation.
[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!!]


As another poster have written, good luck! ;-)

Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4338
by: Graham Banks | last post by:
Does using multiple inheritance introduce any more performance overhead than single inheritance?
4
2404
by: Leslaw Bieniasz | last post by:
Cracow, 20.09.2004 Hello, I need to implement a library containing a hierarchy of classes together with some binary operations on objects. To fix attention, let me assume that it is a hierarchy of algebraic matrices with the addition operation. Thus, I want to have a virtual base class class Matr;
3
3404
by: Chris Capel | last post by:
When is it appropriate to use virtual functions, and when more appropriate to use interfaces? Of course, there are the cases where only a derived class could have any use for the functions, and there are the cases where the functions in the interface need to be called on objects in different inheritence branches, but isn't there a grey area in there? Where to draw the line? Chris "NotYetaNurd" <NotYetaNurd@Matrix.com> wrote in message
22
23383
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete examples?
5
1436
by: Bob Rundle | last post by:
I heard that managed C++ in VS 2005 supports multiple inheritence. Is this true? Bob Rundle
6
1824
by: G.Ashok | last post by:
Hi, Does anybody know how Multiple polymorphism can be done in VB.NET or DOT doesn't support it? Is there any third party extensions available like for Java to do this? Regards, ....Ashok ------------------------------------------------------------------------ "It is beautiful for an engineer to shape and design the same way
5
2124
by: Neelesh Bodas | last post by:
This might be slightly off-topic. Many books on C++ consider multiple inheritence as an "advanced" concept. Bruce Eckel says in TICPP, volume 2 that "there was (and still is) a lot of disagreement about whether is essential in C++". Are there any disadvantages of using multiple inheritence?
2
3389
by: sarathy | last post by:
Hi all, I need a small clarification reg. Templates and Polymorphism. I believe templates is really a good feature, which can be used to implement generic functions and classes. But i doubt whether it should not be used in certain cases. Consider the case when all the params to a template function/class are similar. My questions is that whatever can be acheived by a template in such a case, can be acheived by runtime polymorphism....
47
4033
by: Larry Smith | last post by:
I just read a blurb in MSDN under the C++ "ref" keyword which states that: "Under the CLR object model, only public single inheritance is supported". Does this mean that no .NET class can ever support multiple inheritance. In C++ for instance I noticed that the compiler flags an error if you use the "ref" keyword on a class with multiple base classes. This supports the above quote. However, under the "CodeClass2.Bases" property (part...
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10156
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9951
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7375
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5419
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.