The effect of ref

mipri mipri at minimaltype.com
Fri Nov 22 03:48:19 UTC 2019


On Friday, 22 November 2019 at 03:42:26 UTC, dokutoku wrote:
> Is there a difference in the execution speed and stability when 
> executing the program by rewriting the parameter of the 
> function argument like this?
>
>
> ```d
> void test1 (int * X)
> {
> 	// some processing
> }
>
> void test2 (ref int X)
> {
> 	// some processing
> }
> ```

The Compiler Explorer supports D, so it's a good way to
ask these questions.

https://godbolt.org/z/gnR6Eu

int example.test1(int*):
         mov     eax, DWORD PTR [rdi]
         imul    eax, eax
         add     eax, 1
         ret
int example.test2(ref int):
         mov     eax, DWORD PTR [rdi]
         imul    eax, eax
         add     eax, 1
         ret


More information about the Digitalmars-d-learn mailing list