I really hope someone can help me out as this is a major break point in my development process. I've been googling for info to no avail, and sadly my knowledge reaches a certain extent, being self-taught.
I've been working with IL lately, and I came to the point where optimization was needed (since I'm working in a real-time 3d environment).
The code - which was working (thanks to S. Senthil Kumar) - contained ldarg_0 instructions. Too many in my opinion, since the argument was already loaded onto the stack, as far as I know.I was passing to the dynamic method an object array (defined as params object[] in the delegate).
Argument: object[] objectParams
ldc.I4 1
ldelem_ref
call (calling some method included in the objectParams[1] object)
| Code: |
| ldsfld m_MyField ldc.I4 0 ldelem_ref |
So, I should have three values in my stack, in this sequence: m_MyField (object[]), 0, m_MyField[0]
If I were to pop twice, the current value in the stack should be m_MyField, right?
So that this could would be right:
| Code: |
| ldsfld m_MyField ldc.I4 0 ldelem_ref pop pop //back to m_MyField, I can load the next array item //the stack is containing the m_MyField array ldc.I4 1 ldelem_ref call (some method contained in the referenced object)pop pop |
Here's a ILStream excerpt:
IL_0000: /* 7e | 04000002 */ ldsfld System.Object[] m_MSILMethodTemporaryParamField/Dreams.PlugInManager
IL_0005: /* 20 | 00000000 */ ldc.i4 0
IL_000a: /* 9a | */ ldelem.ref
IL_000b: /* 28 | 06000003 */ call Void PreRender()/Dreams.UserInterface.UserInterface
IL_0010: /* 26 | */ pop
IL_0011: /* 26 | */ pop
IL_0012: /* 20 | 00000001 */ ldc.i4 1
IL_0017: /* 9a | */ ldelem.ref
IL_0018: /* 28 | 06000004 */ call Void PreRender()/Dreams.UserInterface.UserInterfaceEditor
IL_001d: /* 26 | */ pop
IL_001e: /* 26 | */ pop
IL_001f: /* 2a | */ ret
Any help is much, much appreciated.
Thanks for your time.