Search code examples
c#c++calling-convention

__fastcall convention within c#


Considering that:

Microsoft Specific

The __fastcall calling convention specifies that arguments to functions are to be passed in registers, when possible. The following list shows the implementation of this calling convention.

And that the read/write time in a register is way faster than in a stack, do we have any __fastcall equivalent in C#?


Solution

  • Not directly, C# mostly uses what would be equivalent to MSVC++'s __stdcall convention. It can however be "fixed", though in a relatively dirty way (note that example is for __cdecl).

    It's probably best this way, though. In a high-level language like C# (heck, even in most C++ programs) this is an optimization best left for the compiler. A forced calling convention can often make things worse. And even when it helps, it usually doesn't buy you much, at least in the C and C++ programs where I have used it.