.net - Why won't C# inline functions with struct parameters? -
We learn that C # methods with Strapt write not as a formal parameter Is it due to the potential dependence on the stack It is, e.g. For recurring? If so, can I benefit by changing the structure criteria in such ref parameters?
Public int short {return array 1 [i] + array 2 [i]; }
turns:
amount public int (ref Int i) {return array 1 [i] + array 2 [i]; }
Edit: I went to a test, but I can not find anything inline. Here's what I've tried:
class program {Private Static String Results; Static zero main (string [] args) {Console.WriteLine (MethodBase.GetCurrentMethod (.name)); Console.WriteLine (); M1 (); Console.WriteLine (results); } Private Static Zero M1 () {Results = MethodBase.GetCurrentMethod (). Name; }}
It prints "M1" as the second line, which indicates that they did not inline. I made a release build and took any idea with it Ctrl-F5 (to not attach the debugger)?
As John said, it would have a very old post I can confirm the following code:
Using the system; Using System.Runtime.CompilerServices; Straight mystate {public mystread (int p) {x = p; } Public int x; // prevents the optimization of the whole thing. [MethodImpl (MethodImplOptions.NoInlining)] Stable Intams () {New Random (Back). next (); } Fixed Zero main (string [] args) {MyStruct x = New MyStruct (GetSomeNumber ()); // The following line is to prevent further optimization: for (int i = inlinetate (x); i! = 100; i / = 2); } Fixed int inlineast (Mystrut X) {return x.x + 1; }}
inlinetest
method is inline.
The main method disassembly:
; Set stack frame: Push EBP 00000001 mov ebp, esp; 00000000; Receive the call number: 00000003 Call Dwarver PTR DS: [005132 D8H]; Inlined function: 00000009 inc eax; Dummy loop: 0000000a CMP EX, 64 g 0000000 DJ 0000001 B 0000000 F Sir EX, 1 00,000,011 June 00,000,016 00,000,013 ADC EX, 0 00,000,016 CMP EX, 64 g 00000019 JN 0000000 F 0000001 B pop EBP 0000001 CR
I tested it on X86 NAT Framework 3.5 SP1 on Windows 7 x 64 RC.
As I believe that struct
is nothing wrong in inline methods parameters may, JIT that time is not smart enough.
Comments
Post a Comment