Does the value of the structure pass acceptable optimization to the method as a reference in C #?

Let's say I have a structure:

struct MyStruct
{
    public int X
    public int Y
}

And a method in some class that repeats many times elsewhere:

public bool MyMethod( MyStruct myStruct )
{
    return ...
}

Does MyMethod Signature Change to Acceptable Optimization?

public bool MyMethod( ref MyStruct myStruct )

If so, how much would this be an advantage? If not, how many fields would the structure need for a sufficiently large advantage, using refthis way?

+3
source share
5 answers

Since you have clearly asked the question, is this acceptable ...

. ref, ; ref .NET() , .

, , "" ( ...). ​​ ?

( . - !).NET . ++.

+4

, 8 4 32- . , 64- . /, , , .

, . , MyMethod .

, , MyMethod, , , , , - .

+7

, . 64- , . 32- . , , . , , ymmv.

, 16 . , , . , , , ( , ), . . , .

+2

int , , . .

Int, . , , , .

0

, : . , - - , (: XNA) -. GC , ( ) .

, , , ref " " ( .NET , , XNA ). , , , - .

; , . x86 vs x64 - , . , ref , , , JIT - , "ldloc" /stloc ", . .

0

Source: https://habr.com/ru/post/1747048/


All Articles