C# 中的 __fastcall 约定
考虑到:
微软特定
__fastcall 调用约定 指定函数的参数 将在寄存器中传递,当 可能的。下面的列表显示了 这个调用的实现 约定。
而且寄存器中的读/写时间比堆栈中的读/写时间快得多,我们在 C# 中是否有等效的 __fastcall ?
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#?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不是直接使用,C# 主要使用与 MSVC++ 的 __stdcall 约定等效的内容。然而,它可以被“修复”,尽管是以相对肮脏的方式(请注意示例为 __cdecl)。
不过,这样可能是最好的。在像 C# 这样的高级语言中(哎呀,甚至在大多数 C++ 程序中),这是最好留给编译器的优化。强制调用约定通常会让事情变得更糟。即使它有帮助,通常也不会给你带来太多好处,至少在我使用它的 C 和 C++ 程序中是这样。
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.
__fastcall 会自动使用,但仅在某些条件下使用。这是一篇关于这个主题的有趣文章:
来源
__fastcall is used automatically but only in certain conditions. Here is an interesting article about this subject :
Source
LadaRaider,在 32 位 Arch 上,这意味着“最大寄存器的最大大小为 4 字节”,如果你传递一个需要 8 字节的“Long Long”,它将使用 2 个 4 字节的寄存器,这就是编译器处理它的方式。假设你只能使用 3 个 4 字节的寄存器,因此,你不能传递 2 个“Long Long”变量……有些数据必须进入内存,这要慢得多。
LadaRaider, on 32-bit Arch which means "Maximum size of the biggest registers is 4 Bytes" if u pass an "Long Long" which takes 8 Bytes it will use 2 registers of 4 Bytes, that's how the compiler deals with it. Let's say u get to use only 3 registers of 4 Bytes, so, u can't pass 2 "Long Long" variables for example... Some data will have to go into the memory which is a lot more slower.