July 25, 2004 Re: Are virtual tables really required? | ||||
---|---|---|---|---|
| ||||
Thank you for your verbose reply. It has helped me learn quite a bit! In article <ce08tl$26h1$1@digitaldaemon.com>, Ilya Minkov says... > >parabolis schrieb: > >> And assuming a heap representation of a class is something like this: (which is very close to class ClassInfo in object.d) > >Your assumption is wrong. The heap representation of a class consists of I think perhaps I should have been more specific. ClassInfo represents static class data as opposed to an instantiated object, which would have a reference to ClassInfo and the instance's data (including monitor). I am sorry for not making this more clear. >What you describe is how virtual function tables work... so i don't see the point of your post, you just described how to replace virtual function tables by less efficient virtual function tables. > >Perhaps i misunderstood something, so please reformulate your question. My question is whether an inheritance walk is ever a part of calling a function. I see no reason why calling a function at runtime should ever be more involved than fetching the function's address from a static table. However I am under the (incorrect?) impression that virtual function tables occasionally require a lookup in a super class. The point of my post was to figure out whether this is actually the case for single inheritance languages (like D). >> Why would a language with only single inheritence need virtual tables? > >And why would a language with multiple inheritance need virtual tables? In my DerivedEx example (from previous post) any class that extends object (which is in fact every class), the first 4 function table entries for the class are always: ---------------- table[0] print table[1] toString table[2] toHash table[3] cmp ---------------- So code in a derived class that calls print() would simply call table[0]. I believe that a language with multiple inheritance (like C++) would not be able to make any similar assumptions about the contents of the function pointer table. Consider the C++ example: ---------------- class Base1 { virtual int baseFunc1() { return 1; } } class Base2 { virtual int baseFunc2() { return 2; } } class Derived1 extends Base1 { int derivedFunc1() { baseFunc2(); } } class Derived2 extends Base2 { int derivedFunc2() { baseFunc2(); } } class Derived12 extends Base1, Base2 { int derivedFunc12() { return baseFunc1() + baseFunc2(); } } ---------------- What function is in table[0] for Derived1, Derived2 and Derived12? Isnt it impossible to tell without looking at super class info? Thanks again for the post. It really helped me understand this better. |
Copyright © 1999-2021 by the D Language Foundation