clr

Why value types can't be null

强颜欢笑 提交于 2019-12-29 05:45:10
问题 I know that it is possible to have Nullable value types that wraps the value type and gives ability to store null. But is there a technical reason do not allow the value type to be null or the reason is only conceptual? 回答1: A reference type is storeed as a reference (like a pointer) to an object instance. null means a reference that isn't pointing to an instance of an object. Value types are stored as the values themselves, without any references. Therefore, it doesn't make sense to have a

.NET Free memory usage (how to prevent overallocation / release memory to the OS)

邮差的信 提交于 2019-12-29 03:38:11
问题 I'm currently working on a website that makes large use of cached data to avoid roundtrips. At startup we get a "large" graph (hundreds of thouthands of different kinds of objects). Those objects are retrieved over WCF and deserialized (we use protocol buffers for serialization) I'm using redgate's memory profiler to debug memory issues (the memory didn't seem to fit with how much memory we should need "after" we're done initializing and end up with this report Now what we can gather from

CLR implementation of virtual method calls to interface members

百般思念 提交于 2019-12-29 02:41:21
问题 Out of curiosity: how does the CLR dispatch virtual method calls to interface members to the correct implementation? I know about the VTable that the CLR maintains for each type with method slots for each method, and the fact that for each interface it has an additional list of method slots that point to the associated interface method implementations. But I don't understand the following: how does the CLR efficiently determine which interface method slot list to pick from the type's VTable?

Does C# inline properties?

不问归期 提交于 2019-12-28 14:44:16
问题 Does C# inline access to properties? I'm aware of the 32 byte (instruction?) limit on the JIT for inlining, but will it inline properties or just pure method calls? 回答1: It's up to the JIT (the C# compiler doesn't do any inlining as far as I'm aware), but I believe the JIT will inline trivial properties in most cases. Note that it won't inline members of types deriving from MarshalByRefObject which includes System.Windows.Forms.Control (via System.ComponentModel.Component ). I've also seen

Can you have multiple enum values for the same integer? [duplicate]

走远了吗. 提交于 2019-12-28 06:37:24
问题 This question already has answers here : Non-unique enum values (6 answers) Closed 6 years ago . In .NET can you have multiple enum values for the same integer? eg. public enum PersonGender { Unknown = 0, Male = 1, Female = 2, Intersex = 3, Indeterminate = 3, NonStated = 9, InadequatelyDescribed = 9 } 回答1: In C#, this is allowed, as per the C# Language Specication, version 4. Section 1.10 Enums doesn't mention the possibility but later on in section 14 Enums , we see (in 14.3 ): Multiple enum

How to see code of method which marked as MethodImplOptions.InternalCall?

大城市里の小女人 提交于 2019-12-28 06:28:34
问题 When use ILSpy to check the code of System.String, I found there are some methods marked as MethodImplOptions.InternalCall such as: [SecurityCritical] [MethodImpl(MethodImplOptions.InternalCall)] internal static extern int nativeCompareOrdinalEx(string strA, int indexA, string strB, int indexB, int count); I know MethodImplOptions.InternalCall means this method is implemented natively by the common language runtime to optimized code to improve performance. My question is: Is that anyway can

Is there a way to retrieve a C# app's current memory usage?

核能气质少年 提交于 2019-12-28 06:17:52
问题 I am automating some profiling tasks and want to log heap space and generation sizes real-time. The profiling API seems awfully complicated for what I need, and it seems to listen in on individual allocations and collections, which isn't that important to me. Profiling tools are a great help of course, but I was looking for a more flexible, programmable interface. 回答1: The term 'current memory usage' is a little loosely defined. Do you mean the working set? Whatever it means, you can use

What is the maximum length of a C#/CLI identifier?

删除回忆录丶 提交于 2019-12-28 04:22:05
问题 Which other restrictions are there on names (beside the obvious uniqueness within a scope)? Where are those defined? 回答1: From the PDF of ECMA-335, Partition II, section 22, "Metadata preserves name strings, as created by a compiler or code generator, unchanged. Essentially, it treats each string as an opaque blob. In particular, it preserves case. The CLI imposes no limit on the length of names stored in metadata and subsequently processed by the CLI". If I've read this correctly and the

How are DLLs loaded by the CLR?

痞子三分冷 提交于 2019-12-28 02:39:13
问题 My assumption was always that the CLR loaded all of the DLLs it needed on startup of the app domain. However, I've written an example that makes me question this assumption. I start up my application and check to see how many modules are loaded. Process[] ObjModulesList; ProcessModuleCollection ObjModulesOrig; //Get all modules inside the process ObjModulesList = Process.GetProcessesByName("MyProcessName"); // Populate the module collection. ObjModulesOrig = ObjModulesList[0].Modules; Console

How to Invoke ICorDebug

蹲街弑〆低调 提交于 2019-12-25 18:34:12
问题 In "MDbg Sample.zip" projects, invoke the function from COM Module as: [ComImport, Guid("3D6F5F61-7538-11D3-8D5B-00104B35E7EF"), InterfaceType((short) 1)] public interface ICorDebug { ... } The question is where to find the Guid("3D6F5F61-7538-11D3-8D5B-00104B35E7EF"), i can not find it in the regedit, but how to connect the ICoreDebug interface with the COM module? 回答1: It's not in the registry. That guid is the IID, ICorDebug doesn't support remote access so there is no reason to register a