gpt4 book ai didi

CLR/快速调用 : How are large value types passed internally to called functions?

转载 作者:行者123 更新时间:2023-12-04 17:41:11 25 4
gpt4 key购买 nike

只是出于好奇:值类型通常被复制,并且 JIT 编译器在调用方法时似乎使用 Microsoft 的 Fastcall 调用约定。这会将前几个参数放入寄存器中,以便快速访问。但是大值类型(即大于寄存器大小或堆栈宽度)如何传递给被调用函数?


This book excerpt指出:

The CLR's jitted code uses the fastcall Windows calling convention. This permits the caller to supply the first two arguments (including this in the case of instance methods) in the machine's ECX and EDX registers.

最佳答案

就是__clrcall,确实类似于__fastcall。 x86 抖动(ecx、edx)使用了两个寄存器。 x64 jitter (ecx, edx, r8, r9) 的四个寄存器,与原生 x64 调用约定相同。大值类型(如 Decimal 和大结构)通过在调用者堆栈上保留空间、将值复制到其中并传递指向此副本的指针来传递。被调用者再次将其复制到自己的栈帧中。

这是昂贵的,这就是微软建议结构不应大于 16 字节的原因。有意通过 ref 传递结构以避免复制是一种解决方法,通常在 C 和 C++ 中也这样做。以额外的指针取消引用为代价。

关于CLR/快速调用 : How are large value types passed internally to called functions?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8038397/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com