clr

Overlaying several CLR reference fields with each other in explicit struct?

时光总嘲笑我的痴心妄想 提交于 2019-12-21 03:53:08
问题 Edit: I'm well aware of that this works very well with value types, my specific question is about using this for reference types. Edit2: I'm also aware that you can't overlay reference types and value types in a struct, this is just for the case of overlaying several reference type fields with each other. I've been tinkering around with structs in .NET/C#, and I just found out that you can do this: using System; using System.Runtime.InteropServices; namespace ConsoleApplication1 { class Foo {

Overlaying several CLR reference fields with each other in explicit struct?

狂风中的少年 提交于 2019-12-21 03:53:01
问题 Edit: I'm well aware of that this works very well with value types, my specific question is about using this for reference types. Edit2: I'm also aware that you can't overlay reference types and value types in a struct, this is just for the case of overlaying several reference type fields with each other. I've been tinkering around with structs in .NET/C#, and I just found out that you can do this: using System; using System.Runtime.InteropServices; namespace ConsoleApplication1 { class Foo {

Do all C# casts result in boxing/unboxing

[亡魂溺海] 提交于 2019-12-20 18:34:57
问题 I am curious to know if all casts in C# result in boxing, and if not, are all casts a costly operation? Example taken from Boxing and Unboxing (C# Programming Guide) int i = 123; // The following line boxes i. object o = i; This line obviously causes boxing (wrapping up the int type as an object). This is an operation that is considered costly, since it creates garbage that will be collected. What about casts from 2 different types of reference types? what is the cost of that? can it be

Why would the .NET JIT compiler decide to not inline or optimize away calls to empty static methods that have no side effects?

时光怂恿深爱的人放手 提交于 2019-12-20 11:10:41
问题 I think I'm observing the .NET JIT compiler not inlining or optimizing away calls to empty static methods that have no side effects, which is a bit surprising given some bespoken online resources. My environment is Visual Studio 2013 on x64, Windows 8.1, .NET Framework 4.5. Given this simple test program (https://ideone.com/2BRCpC) class Program { static void EmptyBody() { } static void Main() { EmptyBody(); } } A release build with optimizations of the above program produces the following

Why would the .NET JIT compiler decide to not inline or optimize away calls to empty static methods that have no side effects?

拜拜、爱过 提交于 2019-12-20 11:10:06
问题 I think I'm observing the .NET JIT compiler not inlining or optimizing away calls to empty static methods that have no side effects, which is a bit surprising given some bespoken online resources. My environment is Visual Studio 2013 on x64, Windows 8.1, .NET Framework 4.5. Given this simple test program (https://ideone.com/2BRCpC) class Program { static void EmptyBody() { } static void Main() { EmptyBody(); } } A release build with optimizations of the above program produces the following

How to late bind 32bit/64 bit libs at runtime

佐手、 提交于 2019-12-20 10:41:39
问题 I've got a problem similar to,but subtly different from, that described here (Loading assemblies and their dependencies). I have a C++ DLL for 3D rendering that is what we sell to customers. For .NET users we will have a CLR wrapper around it. The C++ DLL can be built in both 32 and 64bit versions, but I think this means we need to have two CLR wrappers since the CLR binds to a specific DLL? Say now our customer has a .NET app that can be either 32 or 64bit, and that it being a pure .NET app

how virtual generic method call is implemented?

左心房为你撑大大i 提交于 2019-12-20 10:28:18
问题 I'm interesting in how CLR implementes the calls like this: abstract class A { public abstract void Foo<T, U, V>(); } A a = ... a.Foo<int, string, decimal>(); // <=== ? Is this call cause an some kind of hash map lookup by type parameters tokens as the keys and compiled generic method specialization (one for all reference types and the different code for all the value types) as the values? 回答1: I didn't find much exact information about this, so much of this answer is based on the excellent

Memory allocation when using foreach loops in C#

橙三吉。 提交于 2019-12-20 10:25:46
问题 I know the basics on how foreach loops work in C# (How do foreach loops work in C#) I am wondering whether using foreach allocates memory that may cause garbage collections? (for all built in System types). For example, using Reflector on the System.Collections.Generic.List<T> class, here's the implementation of GetEnumerator: public Enumerator<T> GetEnumerator() { return new Enumerator<T>((List<T>) this); } On every usage this allocates a new Enumerator (and more garbage). Do all types do

How does Parrot compare to other virtual machines?

笑着哭i 提交于 2019-12-20 09:14:40
问题 Parrot is the virtual machine originally designed for Perl 6. What technical capabilities does the Parrot VM offer that competing virtual machines such as the Java Virtual Machine (JVM)/Hotspot VM and Common Language Runtime (CLR) lack? 回答1: The following answer was written in 2009. See also this 2015 update by raiph. To expand on @Reed and point out some highlights, Parrot's opcodes are at a far higher level than most virtual machines. For example, while most machines store integers and

How does Parrot compare to other virtual machines?

六月ゝ 毕业季﹏ 提交于 2019-12-20 09:14:17
问题 Parrot is the virtual machine originally designed for Perl 6. What technical capabilities does the Parrot VM offer that competing virtual machines such as the Java Virtual Machine (JVM)/Hotspot VM and Common Language Runtime (CLR) lack? 回答1: The following answer was written in 2009. See also this 2015 update by raiph. To expand on @Reed and point out some highlights, Parrot's opcodes are at a far higher level than most virtual machines. For example, while most machines store integers and