From 8279921681383402335
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,d172be9423d7e292,start
X-Google-Attributes: gidf78e5,public
From: "Chris Minnoy" <cminnoy@starlab.net>
Subject: virtual versus dynamic
Date: 1999/02/01
Message-ID: <917861033.740809@saturn.riv.be>#1/1
X-Deja-AN: 439501088
Cache-Post-Path: saturn.riv.be!unknown@sz133.starlab.net
Approved: Fergus Henderson <fjh@cs.mu.oz.au>
X-Original-Date: Mon, 1 Feb 1999 10:14:43 +0100
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
X-Complaints-To: news@news.unimelb.edu.au
X-Trace: izvestia.its.unimelb.edu.au 917904686 5103 128.250.29.17 (1 Feb 1999 21:31:26 GMT)
Organization: Riverland
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUANrYdFuEDnX0m9pzZAQGhBwF9GhW4lqNiA2ZH2LvYef8iTju6EBLkMjb8 cXr6mx+0HlZ/qvVHHZVX2c577TzePzb3 =jQ5g
NNTP-Posting-Date: 1 Feb 1999 21:31:26 GMT
Newsgroups: comp.std.c++

While I was experimenting with Delphi I noticed a rather remarkable feature
that C++ doesn't support, namely dynamic methods. Dynamic methods are, just
like virtual methods, late binded. The difference is size and speed.
In the Delphi helpfile I found:

A method is made dynamic by including a dynamic directive in its declaration.
Dynamic methods are semantically identical to virtual methods.
Virtual and dynamic methods differ only in the implementation of method call
dispatching at runtime; for all other purposes, the two types of methods can
be considered equivalent. In the implementation of virtual methods, the
compiler favors speed of call dispatching over code size. The
implementation of dynamic methods on the other hand favors code size
over speed of call dispatching.

In general, virtual methods are the most efficient way to implement
polymorphic behavior. Dynamic methods are useful only in situations
where a base class declares a large number of virtual methods, and an
application declares a large number of descendant classes with few
overrides of the inherited virtual methods.

Dynamic methods are virtual methods with a slightly different dispatch
mechanism.  Because dynamic methods don't have entries in the object's
virtual method table, they can reduce the amount of memory that objects
consume. However, dispatching dynamic methods is somewhat slower than
dispatching regular virtual methods.  If a method is called frequently,
or if its execution is time-critical, you should probably declare it as
virtual rather than dynamic.  Objects must store the addresses of their
dynamic methods. But instead of receiving entries in the virtual method
table, dynamic methods are listed separately. The dynamic method list
contains entries only for methods introduced or overridden by a
particular class. (The virtual method table, in contrast, includes all
of the object's virtual methods, both inherited and introduced.)
Inherited dynamic methods are dispatched by searching each ancestor's
dynamic method list, working backwards through the inheritance tree.


Maybe it's worthwhile to explore the possibility to include such a
feature also in C++. C++ always claims to be efficient with it's
resources, and this feature seams to increase the resource handling
capability (speed versus size).
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]



