Re: Vtable for virtual functions in D

2018-04-03 Thread Kagamin via Digitalmars-d
On Wednesday, 7 March 2018 at 22:02:17 UTC, sarn wrote: When I wrote Xanthe a year ago, I rolled my own classes using alias this and explicit vtables: https://gitlab.com/sarneaud/xanthe/blob/master/src/game/rigid_body.d#L15 (I did this because normal D classes use the druntime library, and Xant

Re: Vtable for virtual functions in D

2018-04-03 Thread Kagamin via Digitalmars-d
On Monday, 2 April 2018 at 07:02:07 UTC, sarn wrote: I decided to pull some basic background info about vtables, etc, into its own post. I'll write about taking advantage of alias this and template metaprogramming in a later post. https://theartofmachinery.com/2018/04/02/inheritance_and_polymo

Re: Vtable for virtual functions in D

2018-04-03 Thread sarn via Digitalmars-d
On Tuesday, 3 April 2018 at 00:22:52 UTC, Mike Franklin wrote: I'm curious about this comment in the code: Unfortunately, "protected" doesn't work, so a lot of members end up being public. This seems to just be an oversight in the language, so maybe it will change in future versions of D. W

Re: Vtable for virtual functions in D

2018-04-02 Thread Laeeth Isharc via Digitalmars-d
On Wednesday, 7 March 2018 at 21:14:12 UTC, Henrik wrote: Many important libraries like ICU have C interfaces even when written in C++. The direct support of C headers would be very convenient in migrating parts of C/C++ projects to D. It would also open up POSIX which is used extensively i

Re: Vtable for virtual functions in D

2018-04-02 Thread Mike Franklin via Digitalmars-d
On Wednesday, 7 March 2018 at 22:02:17 UTC, sarn wrote: When I wrote Xanthe a year ago, I rolled my own classes using alias this and explicit vtables: https://gitlab.com/sarneaud/xanthe/blob/master/src/game/rigid_body.d#L15 (I did this because normal D classes use the druntime library, and Xan

Re: Vtable for virtual functions in D

2018-04-02 Thread Mike Franklin via Digitalmars-d
On Monday, 2 April 2018 at 07:02:07 UTC, sarn wrote: On Thursday, 8 March 2018 at 22:07:24 UTC, sarn wrote: On Thursday, 8 March 2018 at 04:37:08 UTC, Mike Franklin wrote: Nice! I was thinking about something almost exactly like this recently since 2.079.0 has features to further decouple the

Re: Vtable for virtual functions in D

2018-04-02 Thread sarn via Digitalmars-d
On Thursday, 8 March 2018 at 22:07:24 UTC, sarn wrote: On Thursday, 8 March 2018 at 04:37:08 UTC, Mike Franklin wrote: Nice! I was thinking about something almost exactly like this recently since 2.079.0 has features to further decouple the language from the runtime. It would be nice to read

Re: Vtable for virtual functions in D

2018-03-09 Thread Manu via Digitalmars-d
On 8 March 2018 at 14:56, Henrik via Digitalmars-d wrote: > > It all works good, but why do I have to put the @nogc on the constructor and > destructor separately? @nogc in the global scope does not propagate inside the class (this could lead to serious problems). You can use `@nogc:` at the top

Re: Vtable for virtual functions in D

2018-03-08 Thread sarn via Digitalmars-d
On Thursday, 8 March 2018 at 22:56:27 UTC, Henrik wrote: why do I have to put the @nogc on the constructor and destructor separately? You can make things slightly better by putting @nogc in the struct itself: struct S { @nogc: void member1() { } void member2() { } } But, yea

Re: Vtable for virtual functions in D

2018-03-08 Thread Henrik via Digitalmars-d
On Wednesday, 7 March 2018 at 22:02:17 UTC, sarn wrote: On Wednesday, 7 March 2018 at 12:49:40 UTC, Guillaume Piolat wrote: If you know enough D maybe you can implement your own virtual functions on top of D structs. It seems no one has made it yet. When I wrote Xanthe a year ago, I rolled my

Re: Vtable for virtual functions in D

2018-03-08 Thread sarn via Digitalmars-d
On Thursday, 8 March 2018 at 04:37:08 UTC, Mike Franklin wrote: Nice! I was thinking about something almost exactly like this recently since 2.079.0 has features to further decouple the language from the runtime. It would be nice to read a blog post about this technique. Mike I didn't rea

Re: Vtable for virtual functions in D

2018-03-08 Thread Guillaume Piolat via Digitalmars-d
On Wednesday, 7 March 2018 at 22:02:17 UTC, sarn wrote: On Wednesday, 7 March 2018 at 12:49:40 UTC, Guillaume Piolat wrote: If you know enough D maybe you can implement your own virtual functions on top of D structs. It seems no one has made it yet. When I wrote Xanthe a year ago, I rolled my

Re: Vtable for virtual functions in D

2018-03-07 Thread Mike Franklin via Digitalmars-d
On Wednesday, 7 March 2018 at 22:02:17 UTC, sarn wrote: When I wrote Xanthe a year ago, I rolled my own classes using alias this and explicit vtables: https://gitlab.com/sarneaud/xanthe/blob/master/src/game/rigid_body.d#L15 (I did this because normal D classes use the druntime library, and Xan

Re: Vtable for virtual functions in D

2018-03-07 Thread H. S. Teoh via Digitalmars-d
On Wed, Mar 07, 2018 at 09:14:12PM +, Henrik via Digitalmars-d wrote: [...] > The direct support of C headers would be very convenient in migrating > parts of C/C++ projects to D. It would also open up POSIX which is > used extensively in our work. [...] There's already core.sys.posix.*, which

Re: Vtable for virtual functions in D

2018-03-07 Thread sarn via Digitalmars-d
On Wednesday, 7 March 2018 at 12:49:40 UTC, Guillaume Piolat wrote: If you know enough D maybe you can implement your own virtual functions on top of D structs. It seems no one has made it yet. When I wrote Xanthe a year ago, I rolled my own classes using alias this and explicit vtables: http

Re: Vtable for virtual functions in D

2018-03-07 Thread Henrik via Digitalmars-d
Hi everyone, thank you all for your great answers. I'm playing around with @nogc right now, and it looks really promising. Strings and static arrays all seem to be located on the stack, which is so much better compared to std::string and std::vector in C++. The double indirection for virtual

Re: Vtable for virtual functions in D

2018-03-07 Thread Guillaume Piolat via Digitalmars-d
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? Yes, except without multiple inheritance / virtual inheritance. If yes, can someone explain the advantages of this strategy? A f

Re: Vtable for virtual functions in D

2018-03-07 Thread Patrick Schluter via Digitalmars-d
On Tuesday, 6 March 2018 at 21:20:22 UTC, Henrik wrote: 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 crit

Re: Vtable for virtual functions in D

2018-03-07 Thread Patrick Schluter via Digitalmars-d
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

Re: Vtable for virtual functions in D

2018-03-06 Thread sarn via Digitalmars-d
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