7

I know in C++ there are vpointer and vtable. The virtual function table is a list of method pointers to the virtual methods in the class. Each instance of a class has a pointer to the table, which is used when we call a virtual method from the instance.

I want to know how this implemented in C#. As I know the concept of virtual tables are the same. But what about vpointer is GetType() is used instead.

I would appreciate as much details as possible. Thank you.

Adam Crossland
  • 14,198
  • 3
  • 44
  • 54
NDeveloper
  • 1,837
  • 4
  • 20
  • 34

2 Answers2

7

Vtables are one possible approach in C++, they are not mandated by the C++ standard. The approach .NET uses clearly meets the published standards for the CLI and C#, but the implementation details are not specified (and could potentially change).

You can infer some details from the way that interfaces, overridden members and "new" members work.

Why do you want to know this? If you have a specific problem then stating the problem will allow others to address that directly.

Richard
  • 106,783
  • 21
  • 203
  • 265
1

Take a look at their documentation in the C# spec: 10.5.3 Virtual Methods (although it's the spec not the implementation).

STW
  • 44,917
  • 17
  • 105
  • 161