Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7667077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:00:25+00:00 2026-05-31T15:00:25+00:00

Out of curiosity: how does the CLR dispatch virtual method calls to interface members

  • 0

Out of curiosity: how does the CLR dispatch virtual method calls to interface members to the correct implementation?

I know about the VTable that the CLR maintains for each type with method slots for each method, and the fact that for each interface it has an additional list of method slots that point to the associated interface method implementations. But I don’t understand the following: how does the CLR efficiently determine which interface method slot list to pick from the type’s VTable?

The article Drill Into .NET Framework Internals to See How the CLR Creates Runtime Objects from the May 2005 issue of the MSDN Magazine talks about a process-level mapping table IVMap indexed by interface ID. Does this mean that all types in the same process have the same pointer to the same IVMap?

It also states that:

If MyInterface1 is implemented by two classes, there will be two
entries in the IVMap table. The entry will point back to the beginning
of the sub-table embedded within the MyClass method table.

How does the CLR know which entry to pick? Does it do a linear search to find the entry that matches the current type? Or a binary search? Or some kind of direct indexing and have a map with possibly many empty entries in it?

I’ve also read the chapter on Interfaces in CLR via C# 3rd edition but it does not talk about this. Therefore, the answers to this other question do not answer my question.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T15:00:26+00:00Added an answer on May 31, 2026 at 3:00 pm

    .NET Stack

    If you take a look at diagram that was on the linked site, it may make it easier to understand.

    Does this mean that all types in the same process have the same pointer to the same IVMap?

    Yes, since it is at the domain level, it means everything in that AppDomain has the same IVMap.

    How does the CLR know which entry to pick? Does it do a linear search to find the entry that matches the current type? Or a binary search? Or some kind of direct indexing and have a map with possibly many empty entries in it?

    The classes are laid out with offsets, so everything has a relatively set area on where it would be. That makes things easier when looking for methods. It would search the IVMap table and find that method from the interface. From there, it goes to the MethodSlotTable and uses that class’ implementation of the interface. The inteface map for the class holds the metadata, however, the implementation is treated just like any other method.

    Again from the site you linked:

    Each interface implementation will have an entry in IVMap. If MyInterface1 is implemented by two classes, there will be two entries in the IVMap table. The entry will point back to the beginning of the sub-table embedded within the MyClass method table

    This means that each time an interface is implemented it has a unique record in the IVMap which points to the MethodSlotTable which in turn points to the implementation. So it knows which implementation to pick based on the class that is calling it as that IVMap record points to the MethodSlotTable in the class calling the method. So I imagine it is just a linear search through the IVMap to find the correct instance and then they are off and running.


    EDIT: To provide more info on the IVMap.

    Again, from the link in the OP:

    The first 4 bytes of the first InterfaceInfo entry points to the TypeHandle of MyInterface1 (see Figure 9 and Figure 10). The next WORD (2 bytes) is taken up by Flags (where 0 is inherited from parent, and 1 is implemented in the current class). The WORD right after Flags is Start Slot, which is used by the class loader to lay out the interface implementation sub-table.

    So here we have a table where the number is the offset of bytes. This is just one record in the IVMap:

    +----------------------------------+
    | 0 - InterfaceInfo                |
    +----------------------------------+
    | 4 - Parent                       |
    +----------------------------------+
    | 5 - Current Class                |
    +----------------------------------+
    | 6 - Start Slot (2 Bytes)         |
    +----------------------------------+
    

    Suppose there are 100 interface records in this AppDomain and we need to find the implementation for each one. We just compare the 5th byte to see if it matches our current class and if it does, we jump to the code in the 6th byte. Since, each record is 8 bytes long, we would need to do something like this: (Psuedocode)

    findclass :
       if (!position == class) 
          findclass adjust offset by 8 and try again
    

    While it is still a linear search, in reality, it isn’t going to take that long as the size of data being iterated isn’t huge. I hope that helps.


    EDIT2:

    So after looking at the diagram and wondering why there is no Slot 1 in the IVMap for the class in the diagram I re-read the section and found this:

    IVMap is created based on the Interface Map information embedded within the method table. Interface Map is created based on the metadata of the class during the MethodTable layout process. Once typeloading is complete, only IVMap is used in method dispatching.

    So the IVMap for a class is only loaded with the interfaces that the specific class inherits. It looks like it copies from the Domain IVMap but only keeps the interfaces that are pointed to. This brings up another question, how? Chances are it is the equivalent of how C++ does vtables where each entry has an offset and the Interface Map provides a list of the offsets to include in the IVMap.

    If we look at the IVMap that could be for this entire domain:

    +-------------------------+
    | Slot 1 - YourInterface  |
    +-------------------------+
    | Slot 2 - MyInterface    |
    +-------------------------+
    | Slot 3 - MyInterface2   |
    +-------------------------+
    | Slot 4 - YourInterface2 |
    +-------------------------+
    

    Assume there are only 4 implementations of Interface Map in this domain. Each slot would have an offset (similar to the IVMap record I posted earlier) and the IVMap for this class would use those offsets to access the record in the IVMap.

    Assume each slot is 8 bytes with slot 1 starting at 0 so if we wanted to get slot 2 and 3 we would do something like this:

    mov ecx,edi
    mov eax, dword ptr [ecx]
    mov eax, dword ptr [ecx+08h] ; slot 2
    ; do stuff with slot 2
    mov eax, dword ptr [ecx+10h] ; slot 3
    ; do stuff with slot 3
    

    Please excuse my x86 as I’m not that familiar with it but I tried to copy what they have in the article that was linked to.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just out of curiosity, does anyone know a better way of building the following
Just out of curiosity, does anyone know why the AsynchResult type resides in System.Runtime.Remoting.Messaging
Out of curiosity, how exactly does binary code get converted into letters? I know
Out of curiosity, does anyone know which IDE the developers of the Delphi IDE
Just out of curiosity, how does iostream access the input-output system. (I have a
Out of curiosity about reverse engineering, I am thinking of writing a simple program
Just out of curiosity: I know I can tell the compiler if I want
Just out of curiosity, does there exist a valid zip-file (according to format spec)
Just out of curiosity I tried overriding a abstract method in base class, and
Just out of curiosity, why does calling IEnumerable.ToList() on an existing List not return

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.