On Monday, 27 June 2016 at 16:10:13 UTC, Ola Fosheim Grøstad wrote:
On Monday, 27 June 2016 at 16:03:44 UTC, luminousone wrote:
C++ post pended vtable pointers, Are not implementation dependent.

I don't know what «post pended vtable pointers» means. Which section of the C++ spec are you referring to?

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4296.pdf

Member name lookup, Virtual functions, some where in their.

When you declare an object,

class a{
  int b;
  int c;
//** the compiler puts a hidden variable here called the vtable pointer **//
  void **vtble;
  virtual void somefunc();
}

All of your virtual functions are referenced from this table; So that inherited classes will call the correct function based on the type of said object and the overrides in said object.

C#, D, put the vtable as the very first item in the base most class, C++ puts this as the last item in the base most class, C# and D use the first item in the vtable for type information generated by the compiler at compile time. Because the vtable is in the same place in ALL objects type reflection is very easy to implement. In C++ the exact position of the vtable depends on what is in the base most class, it might be 8bytes in, maybe 20, maybe 200, you just don't know, And certainly the runtime can't know.

Granted their are really bloated, slow, and memory chugging ways around this, such as storing a list of every allocated object in memory somewhere, and having reflection calls search this using an objects memory address.

Reply via email to