il

Calling method of non-assigned class

六月ゝ 毕业季﹏ 提交于 2019-12-19 07:51:36
问题 I have doubt about these two aspects; First one; Test test = new Test(); result = test.DoWork(_param); Second one; result = new Test().DoWork(_param); What happens if we dont assign the newly created instance to a variable and directly call the method? I see some difference between two way on IL code. This one below is IL output of first c# code IL_0000: ldstr "job " IL_0005: stloc.0 IL_0006: newobj instance void Works.Test::.ctor() IL_000b: stloc.1 IL_000c: ldloc.1 IL_000d: ldloc.0 IL_000e:

IL level code debugger

血红的双手。 提交于 2019-12-18 12:08:15
问题 Is there any IL level debugger in form of a VS plugin or standalone application? Visual studio’s debugger is great, but it allows you to debug on either HLL code level or assembly language, you can’t debug IL. It seems that in some situations it would be useful to have an opportunity to debug at IL level. In particular it might be helpful when debugging a problem in the code that you don't have the source of. It is arguable if it is actually useful to debug IL when you don't have the source,

Why does my application spend 24% of its life doing a null check?

旧城冷巷雨未停 提交于 2019-12-17 21:39:09
问题 I've got a performance critical binary decision tree, and I'd like to focus this question on a single line of code. The code for the binary tree iterator is below with the results from running performance analysis against it. public ScTreeNode GetNodeForState(int rootIndex, float[] inputs) { 0.2% ScTreeNode node = RootNodes[rootIndex].TreeNode; 24.6% while (node.BranchData != null) { 0.2% BranchNodeData b = node.BranchData; 0.5% node = b.Child2; 12.8% if (inputs[b.SplitInputIndex] <= b

Why can I not modify the result of an unboxing conversion?

倾然丶 夕夏残阳落幕 提交于 2019-12-17 13:41:25
问题 struct Point { public int x; public int y; } void Main() { Point p; p.x = 1; p.y = 1; Object o = p; ((Point) o).x = 4; // error ((Point) o).x = 5; // error ((Point) o).x = 6; // error p = (Point) o // expect 6 } Why doesn't it compile to ldloc.1 // o unbox Point ldc.i4.4 stfld Point.x Where C++ CLI allows it. For those who don't know, unbox is not required to create a copy of value types, instead it pushes a pointer to the value on to the stack. Only assignment would create a copy. 回答1:

Why x86 JIT is smarter than x64?

醉酒当歌 提交于 2019-12-14 02:35:34
问题 I'm running a very simple program static void Main(string[] args) { Console.WriteLine(Get4S()); Console.WriteLine(Get4()); } private static int Get4S() { return 4; } private static int Get4() { int res = 0; for (int i = 0; i < 4; i++) { res++; } return res; } when it works under x86 it inlines Get4S method and Get4 asm code is: 00000000 push ebp 00000001 mov ebp,esp 00000003 xor eax,eax 00000005 inc eax 00000006 inc eax 00000007 inc eax 00000008 inc eax 00000009 pop ebp 0000000a ret BUT when

“Specified cast is not valid” only on release build from MS build

纵饮孤独 提交于 2019-12-14 01:28:51
问题 I am getting a "Specified cast is not valid" valid when doing only a release build from MSBuild 4.0. I tested this out in using a release build from Visual Studio 2012 and didn't get this issue. I also tested this out using a debug build from MSBuild 4.0 and didn't get this issue. Exception: Code public abstract class CachedSessionBase : ISessionObject { protected Dictionary<MethodBase, Object> _getAndSetCache = new Dictionary<MethodBase, object>(); protected TResult SetAndGet<TResult>

Reference a collection from IL constructed method

旧街凉风 提交于 2019-12-13 02:49:49
问题 I am building a dynamic method using reflection. Most tutorials and documentation (e.g. How to: Define and Execute Dynamic Methods or Creating method dynamically, and executing it) show a very simple example. I trying to find a way to reference another assembly from the dynamic assembly. For example, I would like to be able to construct the following function by using Reflection.Emit . public static void f(int n) { int[] arr = new arr[n]; return arr.Max(); } What would be the common way of

Is C# namespace compiled into IL files to be “complete” names?

若如初见. 提交于 2019-12-12 11:32:44
问题 E.g, if I have namespace a namespace b { class C... class D... } So after compiling, in IL file, where's the namespace information? Do I get two classes named a.b.C and a.b.D where the class names is prefixed by the namespace name? Or I get a namespace a.b in the assembly file and having class C/class D inside it, just like C# code? 回答1: The other two responses wrote something, so I have to write the opposite :-) Let's say that Microsoft kept the foot in both camps... Reading the ECMA-335:

Why does C# compiler emit additional OpCodes in IL?

孤街醉人 提交于 2019-12-12 10:48:19
问题 If I've a method Multiply defined as: public static class Experiment { public static int Multiply(int a, int b) { return a * b; } } Then why does the compiler emit this IL: .method public hidebysig static int32 Multiply(int32 a, int32 b) cil managed { .maxstack 2 //why is it not 16? .locals init ( [0] int32 CS$1$0000) //what is this? L_0000: nop //why this? L_0001: ldarg.0 L_0002: ldarg.1 L_0003: mul L_0004: stloc.0 //why this? L_0005: br.s L_0007 //why this? L_0007: ldloc.0 //why this? L

Recursion in Windows 7 64 bit

心不动则不痛 提交于 2019-12-12 09:15:37
问题 I have this helper class public static class DateTimeHelper { public static int GetMonthDiffrence(DateTime date1, DateTime date2) { if (date1 > date2) { return getmonthdiffrence(date2, date1); } else { return ((date2.year - date1.year) * 12) + (date2.month - date1.month); } } } The function calculate the number of months between two dates, it do exactly what I want. So far there is no problem. The problem is when I am on release and windows 7 64 bit I get always the same value "0" When I got