Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After considering some other aspects of the system as well such as interfaces in .NET, I am starting to think maybe it's better - perhaps even more-or-less necessary - to not even use the C++ virtual calling mechanism at all. The more I consider, the messier using that mechanism is getting.</p> <p>In this approach, each user object class would have a separate struct for the vtable (perhaps kept in a separate namespace like <code>vtabletype::</code>. The generated class would have a pointer member that would be initialized through some trickery to point to a static instance of the vtable. Virtual calls would explicitly use a member pointer from that vtable.</p> <p>If done properly this should have the same performance as the compiler's own implementation would. I've confirmed it does on VC2008. (By contrast, just using straight C, which is what I was planning on earlier, would likely <em>not</em> perform as well, since compilers often optimize <code>this</code> into a register.)</p> <p>It would be hellish to write code like this manually, but of course this isn't a concern for a generator. This approach does have some advantages in this application:</p> <ul> <li><p>Because it's a much more explicit approach, one can be more sure that it's doing exactly what .NET specifies it should be doing with respect to <code>newslot</code> as well as selection of interface implementations.</p></li> <li><p>It might be more efficient (depending on some internal details) than a more traditional C++ approach to interfaces, which would tend to invoke multiple inheritance.</p></li> <li><p>In .NET, objects are considered to be fully constructed when their <code>.ctor</code> runs. This impacts how virtual functions behave. With explicit knowledge of the vtables, this could be achieved by writing it in during allocation. (Although putting the <code>.ctor</code> code into a normal member function is another option.)</p></li> <li><p>It might avoid redundant data when implementing reflection.</p></li> <li><p>It provides better control and knowledge of object layout, which could be useful for the garbage collector.</p></li> </ul> <p>On the downside, it totally loses the C++ compiler's overloading feature with regard to the vtable entries: those entries are data members, not functions, so there is no overloading. In this case it would be tempting to just number the members (say <code>_0</code>, <code>_1</code>...) This may not be so bad when debugging, since once the pointer is followed, you'll see an actual, properly-named member function anyway.</p> <p>I think I may end up doing it this way but by all means I'd like to hear if there are better options, as this is admittedly a rather complex approach (and problem.)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload