Any real use case for using the calling convention fastcall?
Have you had any real us开发者_如何学编程e case for using the calling convention fastcall?
Thanks.
__fastcall tries to pass the function arguments in the CPU registers instead of the stack if possible, which is faster.
Here's a link to an MSDN article explaining the __fastcall calling convention: http://msdn.microsoft.com/en-us/library/6xa169sk(VS.71).aspx
The first two DWORD or smaller arguments are passed in ECX and EDX registers; all other arguments are passed right to left.
This means this will only work for the first two arguments and only if they're <= 32 Bits.
In general I would say, don't expect any big performance advantages from this.
Here's an article explaining when to use fastcall. It actually specifies a case when you actually have no alternative but to use it:
Some VCL classes, such as TList, allow you to specify a callback function (a sort routine in the case of TList). You will have to use the __fastcall keyword in this case, too, as the VCL expects it.
I have one case where I use it effectively - it's a very small asm routine (3 instructions) which manipulates a single value in a register.
For anything but the very smallest and most performance-critical routines though the calling convention should really make no difference.
精彩评论