title: How does the callvirt .NET instruction work for interfaces?
body: <p>Explaining virtual dispatching to someone is easy: every object has a pointer to a table as part of its data. There are N virtual methods on the class. Every call to a particular method i indexes the object when it arrives and calls the ith method in the table. Every class that implements method X() will have the code for method X() in the same ith index. </p>
  
  <p>But then we get interfaces. And interfaces require some sort of contortion because two non-inheriting classes that both implement the same interface will have the virtual functions in different indexes of the table.</p>
  
  <p>I have searched the Internet, and there are many discussions I can find about how interface dispatching <em>can</em> be implemented. There are two broad categories: 
  a) some sort of hash table look up on the object to find the right dispatch table
  b) when the object is cast to the interface, a new pointer is created that points to the same data but to a different vtable.</p>
  
  <p>But despite lots of info about how it <em>can</em> work, I can find nothing about how the .NET runtime engine actually implements it. </p>
  
  <p>Does anyone know of a document that describes the actual pointer arithmetic that happens at a callvirt instruction when the object type is an interface? </p>