{"id":4714,"date":"2014-03-30T14:50:55","date_gmt":"2014-03-30T14:50:55","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/why-does-net-use-so-much-cpu-is-this-a-problem-collection-of-common-programming-errors\/"},"modified":"2014-03-30T14:50:55","modified_gmt":"2014-03-30T14:50:55","slug":"why-does-net-use-so-much-cpu-is-this-a-problem-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/why-does-net-use-so-much-cpu-is-this-a-problem-collection-of-common-programming-errors\/","title":{"rendered":"Why does .NET use so much CPU, is this a problem?-Collection of common programming errors"},"content":{"rendered":"<p><em>(This was meant to be a general hypothetical question, me whining that .NET was a pig and begging for reasons. It was not really meant to be a question about my specific app.)<\/em><\/p>\n<p>Currently I am rewriting some old C++ code in C#. We are porting over all legacy applications. I have C++ applications that take MAX 3% CPU. Mostly they use none. I then take the code, copy and paste, then reformat to C# syntax and .NET libraries, and BAM! 50% CPU. Whats the reason for this? I thought at first it was JIT, but even after each code path has been exercises, and the whole thing has been JIT ed, same issue.<\/p>\n<p>I have also noticed huge memory increases. Apps that took 9 MB running a full load now start at 10 MB and run at 50 MB. I realize hardware is cheap, but I want to understand what causes this. Is it a cause for alarm, or is .NET just that much the pig?<\/p>\n<p><strong>Update 1 Answer to Skeet<\/strong><\/p>\n<p>I am familiar with C#. I change things to Linq, and so on. I typically take code and reduce the number of lines, and so on. Could you give some more examples of what a C++ person my do wrong in .NET?<\/p>\n<p><strong>Update 2<\/strong><\/p>\n<p>This was meant to be a general question, but the specific app that has the issue is as follows.<\/p>\n<p>It has a thread that uses and ODBC driver to get data from a paradox db. It then uses Linq to transform this to a SQL db and post it. I have run it through ANTS profiler, and it seems the data set filling take the most time. Followed by Linq posting. I know some of my areas are reflection usage, but I don&#8217;t see how to do what I need to with out this. I plan to change my string to string builders. Is there any difference between these two?<\/p>\n<pre><code>(int)datarow[\"Index\"]\n<\/code><\/pre>\n<p>and<\/p>\n<pre><code>ConvertTo.Int32(datarow[\"Index\"])\n<\/code><\/pre>\n<p>I changed all string concatenation to format strings. That didn&#8217;t reduce over head. Does any one know the difference between a data reader vs data adapter and datasets?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>(This was meant to be a general hypothetical question, me whining that .NET was a pig and begging for reasons. It was not really meant to be a question about my specific app.) Currently I am rewriting some old C++ code in C#. We are porting over all legacy applications. I have C++ applications that [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4714","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4714","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4714"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4714\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4714"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4714"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4714"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}