www.digitalmars.com         C & C++   DMDScript  

D - Virtual Function and Class Optimizations

reply Mongryong Lee <Mongryong sympatico.ca> writes:
How well does 'D' optimize classes and functions that are 'virtual'?

For instance:

interface I1 {...}
interface I2 {...}
class A: I1 {...}
class B: A {..}
class C: B, I2 {..}
class D: C {...}

If I only use 'class D', is the compiler smart enough to 'throw away' 
all of the virtual overhead?

Thanks.
Mar 01 2003
next sibling parent "Achillefs Margaritis" <axilmar b-online.gr> writes:
I don't know if it is such a good idea, but I will risk it and dare propose
that vtables are constructed at compile time and not be fixed. I don't know
if it is feasible, but sometimes the following need rises: to subclass an
object that you don't have access to. That means that one could write 'class
extensions' which would not be subclasses.

For example, a GUI dialog contains the following widgets: button, check box,
radio button. If I want to specialize the 'button' behaviour in some way and
the dialog is available to me as a binary only, then I am into deep trouble,
since I would have to replicate the dialog and add my own functionality (or
do hacks like constructing the dialog, then deleting the button and
inserting my own button). But if I could define the 'paint' or 'buttonDown'
virtual method outside of the class but for the same class, then I would not
have that problem.

Now that I  think of it, this system could be extended for even replacing
classes that are binary compatible with other classses.

Another crazy functionality would be to define methods outside of classes!!!
then, the compiler would bind a class and a method only if the method's
variables match the classe's method.

I am sorry If am saying things that can't be implemented, but I haven't
(yet) make my own compiler. I am just thinking as a programmer and say
whatever seems better for my job.


"Mongryong Lee" <Mongryong sympatico.ca> wrote in message
news:3E61536A.6060501 sympatico.ca...
 How well does 'D' optimize classes and functions that are 'virtual'?

 For instance:

 interface I1 {...}
 interface I2 {...}
 class A: I1 {...}
 class B: A {..}
 class C: B, I2 {..}
 class D: C {...}

 If I only use 'class D', is the compiler smart enough to 'throw away'
 all of the virtual overhead?

 Thanks.
Mar 02 2003
prev sibling parent "Walter" <walter digitalmars.com> writes:
"Mongryong Lee" <Mongryong sympatico.ca> wrote in message
news:3E61536A.6060501 sympatico.ca...
 How well does 'D' optimize classes and functions that are 'virtual'?

 For instance:

 interface I1 {...}
 interface I2 {...}
 class A: I1 {...}
 class B: A {..}
 class C: B, I2 {..}
 class D: C {...}

 If I only use 'class D', is the compiler smart enough to 'throw away'
 all of the virtual overhead?
Yes.
Mar 18 2003