Vtable for virtual functions in D

Patrick Schluter Patrick.Schluter at bbox.fr
Wed Mar 7 08:29:04 UTC 2018


On Tuesday, 6 March 2018 at 21:20:22 UTC, Henrik wrote:
> Does anyone know if D is using the vtable implementation for 
> virtual functions just like most C++ compilers? If yes, can 
> someone explain the advantages of this strategy? A function 
> pointer in C is regarded as expensive because of missing 
> inlining, but a double indirection through a vtable just looks 
> insane - if there aren't really good reasons for such an 
> implementation. Does it make class inheritance or class 
> polymorphism much simpler to implement or what is the reason?
>
> I have worked with C in embedded systems for many years now, 
> and for our modern Linux systems we are using a combination of 
> C and Java today. Java for parts where memory safety is more 
> important than speed/determinism, and C for the critical real 
> time parts. There should exist a language between these worlds, 
> where we can achieve memory safety at relatively small costs. 
> C++ is not really an alternative, and D looks much more 
> pleasant for us C programmers than for example Rust.

p0nce[1] has a link to an excellent article explaining in detail 
how the implementation of the vtable, single inheritance with 
interfaces work. The article isn't about D per se but D classes 
use the same mechanism.

[1]: https://p0nce.github.io/d-idioms/#Inside-the-D-Object-Model


More information about the Digitalmars-d mailing list