clr

Why was an interface for arithmetic operations abandon in .NET? [closed]

安稳与你 提交于 2019-12-05 03:39:41
Closed . This question is opinion-based . It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post . Closed 5 years ago . In .NET it is not possible to constrain a generic method so it only accepts numeric types as described in the following question: Is there a constraint that restricts my generic method to numeric types? . But if you look at the reference source for .NET ( http://sourceof.net ) and look at the source code for the primitive types ( Int32 , Int64 , Single , etc) there is a

What is a cast under the hood [duplicate]

青春壹個敷衍的年華 提交于 2019-12-05 03:12:35
Possible Duplicate: C# “as” cast vs classic cast I want to know what happens under the hood of the .Net CLR when I do something like object myObj = "abc"; string myStr = (string)myObj; and how the second line differs from string myStr = myObj.ToString() or string myStr = myObj as string; looking around I found generics answers such as "the compiler inserts code there" but I'm not satisfied... I'm looking for deep undertanding of the cast mechanics... Oh the compiler inserts code? Show me! The compiler optmizes the code? How? When? Pls get as close to the metal as you can!!! You can use IL

Thread.sleep vs Monitor.Wait vs RegisteredWaitHandle?

此生再无相见时 提交于 2019-12-05 02:30:13
(the following items has different goals , but im interesting knowing how they "PAUSEd") questions Thread.sleep - Does it impact performance on a system ?does it tie up a thread with its wait ? what about Monitor.Wait ? what is the difference in the way they "wait"? do they tie up a thread with their wait ? what about RegisteredWaitHandle ? This method accepts a delegate that is executed when a wait handle is signaled. While it’s waiting, it doesn’t tie up a thread. so some thread are paused and can be woken by a delegate , while others just wait ? spin ? can someone please make things clearer

Static field is initialized later when the class has a static constructor

泪湿孤枕 提交于 2019-12-05 02:18:00
问题 By running this simple code: class Program { class MyClassWithStatic { public static int Number = SomeService.GetData(); static MyClassWithStatic() { Console.WriteLine("static ctor runs"); } } class SomeService { public static int GetData() { Console.WriteLine("GetDataRuns"); return 42; } } static void Main(string[] args) { InitService(); var value = MyClassWithStatic.Number; Console.WriteLine(value); } private static void InitService() { Console.WriteLine("InitServiceRuns"); } } The output

How is JIT compiled code injected in memory and executed?

走远了吗. 提交于 2019-12-05 02:02:47
"Consider a typical Windows x86 or AMD64 architecture, the memory is divided in executable sections that cannot be written to and data sections that can be written to but cannot be executed (think DEP)." "JIT compiles methods in-memory, does (generally) not store anything to disk, instead moves it around where the next instruction pointer can reach it, changes the current instruction pointer (pointing to the JIT) to point to the newly generated code and then executes it." These two paragraphs, while a bit over-simplified, are what I basically understand of JIT and Windows' memory model. I also

Visual Studio 2010: Embed Interop Types

末鹿安然 提交于 2019-12-05 01:28:04
I found some information about this on Scott Hanselmans Blog Does anybody exactly know what this mean? Is this only for the Office Primary Interop Assemblies, or can I also use this to Embed my Redemption library or other COM libraries? The process described in Scott Hanselman's blog is called Type Equivalence , a rather nebulous term for the CLR 4.0's support for COM interop type assemblies. Although I haven't had a chance to look at it, there is a video here at Channel 9 that discusses it: Raja Krishnaswamy and Vance Morrison: CLR 4 - Inside Type Equivalence http://channel9.msdn.com/shows

Passing c# string to unmanaged c++ DLL

て烟熏妆下的殇ゞ 提交于 2019-12-05 00:49:19
问题 I have a simple application that loads an unmanaged dll and passes a few string values to it from C#. But in the C++ dll application, I receive an exception :: Tried to access a read/write protected memory. My DLL Import looks like this: [DllImport("X.dll", CallingConvention = CallingConvention.Cdecl) ] public static extern int DumpToDBLogFile([MarshalAs(UnmanagedType.I4)]int loggingLevel, [MarshalAs(UnmanagedType.I4)]int jobId, int threadId, [MarshalAs(UnmanagedType.LPStr)]string procName,

call instead of callvirt in case of the new c# 6 “?” null check

久未见 提交于 2019-12-05 00:35:12
Given the two methods: static void M1(Person p) { if (p != null) { var p1 = p.Name; } } static void M2(Person p) { var p1 = p?.Name; } Why the M1 IL code use callvirt : IL_0007: brfalse.s IL_0012 IL_0009: nop IL_000a: ldarg.0 IL_000b: callvirt instance string ConsoleApplication4.Person::get_Name() and the M2 IL use call : brtrue.s IL_0007 IL_0004: ldnull IL_0005: br.s IL_000d IL_0007: ldarg.0 IL_0008: call instance string ConsoleApplication4.Person::get_Name() I just can guess that it because in M2 we know that p isn't null and its like new MyClass().MyMethod(); Is it true? If it is, what if p

Checking if a file is a .NET assembly

五迷三道 提交于 2019-12-05 00:24:43
I've seen some methods of checking if a PEFile is a .NET assembly by examining the binary structure . Is that the fastest method to test multiple files? I assume that trying to load each file (e.g. via Assembly.ReflectionOnlyLoad ) file might be pretty slow since it'll be loading file type information. Note: I'm looking for a way to check files programmatically. Stormenet Maybe this helps from https://web.archive.org/web/20110930194955/http://www.grimes.demon.co.uk/dotnet/vistaAndDotnet.htm Next, I check to see if it is a .NET assembly. To do this I check to see if the file contains the CLR

What are the implications of using unsafe code

ぃ、小莉子 提交于 2019-12-04 23:51:36
Aside from the fact that the code itself can access memory directly. What are the other implications of using the "/unsafe" compiler flag and the "fixed" keyword? Are there any knock on effects related to code signing and deployment of my .exe (my app is desktop only)? (This isn't about whether or not I should be doing this, the why is covered in my question here ) Unsafe code is not verifiable, so you have to be aware of that. In a Full Trust environment, that's not a big deal, but if you have other environments which have a more restricted permission set, then this might impact you there.