clr

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

好久不见. 提交于 2019-11-27 22:43:44
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. The term 'current memory usage' is a little loosely defined. Do you mean the working set? Whatever it means, you can use different properties such as VirtualMemorySize , WorkingSet , PrivateMemorySize , etc. from the process class to

Why Nullable<T> is a struct?

时间秒杀一切 提交于 2019-11-27 21:56:50
I was wondering why Nullable<T> is a value type, if it is designed to mimic the behavior of reference types? I understand things like GC pressure, but I don't feel convinced - if we want to have int acting like reference, we are probably OK with all the consequences of having real reference type. I can see no reason why Nullable<T> is not just boxed version of T struct. As value type: it still needs to be boxed and unboxed, and more, boxing must be a bit different than with "normal" structs (to treat null-valued nullable like real null ) it needs to be treated differently when checking for

C# StructLayout.Explicit Question

懵懂的女人 提交于 2019-11-27 21:46:26
问题 I'm trying to understand why the second example below works with no issues, but the first example gives me the exception below. It seems to me that both examples should give an exception based on the description. Can anyone enlighten me? Unhandled Exception: System.TypeLoadException: Could not load type 'StructTest.OuterType' from assembly 'StructTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' because it contains an object field at offset 0 that is incorrectly aligned or

Signing .NET assemblies: Does this protect my assembly from tampering really?

对着背影说爱祢 提交于 2019-11-27 21:40:33
问题 I am implementing a "locking" system in my app which protects my app against being copied and used illegally. The system checks the signature of a hardware-based code and expects it to be signed with a Private Key that only my company owns. (The app has got the Public Key to validate the signature.) I want to make sure that no one changes my locking mechanism in the app, so I want to sign my app's assembly and I think it makes sense. Since I haven't seen the CLR ever talk about an assembly's

Where does .NET place the String value?

旧城冷巷雨未停 提交于 2019-11-27 21:20:24
问题 I am using SOS debug extension dll to check the memory layout of a String type, and below is the result. !dso ESP/REG Object Name 0015EFC0 01c6b9cc System.String hello,world !do 01c6b9cc Name: System.String MethodTable: 6de3f9ac EEClass: 6db78bb0 Size: 36(0x24) bytes File: C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089>\mscorlib.dll String: hello,world Fields: MT Field Offset Type VT Attr Value Name 6de42978 40000ed 4 System.Int32 1 instance 11 m_stringLength

.NET Parameter passing - by reference v/s by value

﹥>﹥吖頭↗ 提交于 2019-11-27 21:13:05
问题 I'm trying to validate my understanding of how C#/.NET/CLR treats value types and reference types. I've read so many contradicting explanations I stil This is what I understand today, please correct me if my assumptions are wrong. Value types such as int etc live on the stack, Reference types live on the managed heap however if a reference type has for example has an instance variable of type double, it will live along with its object on the heap The second part is what I am most confused

Possible to merge a DLL into a .NET EXE? [duplicate]

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 20:55:26
This question already has an answer here: Embedding DLLs in a compiled executable 14 answers I have a DLL that stores classes common to two applications. I'd like to keep my application limited to one EXE file and would like to see if I can somehow embed this DLL within my main EXE. How can I embed the external DLL into my application? (if possible) http://www.microsoft.com/downloads/en/details.aspx?FamilyID=22914587-b4ad-4eae-87cf-b14ae6a939b0&displaylang=en ILMerge is a utility for merging multiple .NET assemblies into a single .NET assembly. It works on executables and dlls alike. It comes

Why only literal strings saved in the intern pool by default?

喜你入骨 提交于 2019-11-27 20:26:53
Why by default only literal strings are saved in the intern pool? Example from MSDN : String s1 = "MyTest"; String s2 = new StringBuilder().Append("My").Append("Test").ToString(); String s3 = String.Intern(s2); Console.WriteLine("s1 == '{0}'", s1); Console.WriteLine("s2 == '{0}'", s2); Console.WriteLine("s3 == '{0}'", s3); Console.WriteLine("Is s2 the same reference as s1?: {0}", (Object)s2==(Object)s1); Console.WriteLine("Is s3 the same reference as s1?: {0}", (Object)s3==(Object)s1); /* This example produces the following results: s1 == 'MyTest' s2 == 'MyTest' s3 == 'MyTest' Is s2 the same

.Net 4.0 Windows Application crashes in clr.dll under Windows Server 2008

强颜欢笑 提交于 2019-11-27 20:22:47
问题 I have a Windows application scheduled to run on a daily basis and fails intermittently due to the following log in EventViewer. Faulting application name: MyApplication.exe, version: 1.0.0.0, time stamp: 0x4d54829a Faulting module name: clr.dll, version: 4.0.30319.1, time stamp: 0x4ba21eeb Exception code: 0xc0000005 Fault offset: 0x00000000000029e1 Faulting process id: 0xbb1c Faulting application start time: 0x01cbd99223d8b4eb Faulting application path: E:\MyApplication\MyApplication.exe

Why is String.Concat not optimized to StringBuilder.Append?

泪湿孤枕 提交于 2019-11-27 19:46:27
I found concatenations of constant string expressions are optimized by the compiler into one string. Now with string concatenation of strings only known at run-time, why does the compiler not optimize string concatenation in loops and concatenations of say more than 10 strings to use StringBuilder.Append instead? I mean, it's possible, right? Instantiate a StringBuilder and take each concatenation and turn it into an Append() call. Is there any reason why this should or could not be optimized? What am I missing? The definite answer will have to come from the compiler design team. But let me