{"id":23046,"date":"2022-11-23T10:53:26","date_gmt":"2022-11-23T05:23:26","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-c-how-to-bypass-error-cs0212-cheaply-for-programmers-and-computers\/"},"modified":"2022-11-23T10:53:26","modified_gmt":"2022-11-23T05:23:26","slug":"solved-c-how-to-bypass-error-cs0212-cheaply-for-programmers-and-computers","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-c-how-to-bypass-error-cs0212-cheaply-for-programmers-and-computers\/","title":{"rendered":"[Solved] C# &#8211; How to Bypass Error cs0212 Cheaply for Programmers and Computers?"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-37132614\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"37132614\" data-parentid=\"37109833\" data-score=\"0\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>.NET runtime is a managed execution runtime which (among other things) provides <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/ee787088(v=vs.110).aspx\">garbage collection<\/a>. .NET garbage collector (GC)<br \/>\nnot only manages the allocation and release of memory, but also transparently moves the objects around the &#8220;managed heap&#8221;, blocking<br \/>\nthe rest of your code while doing it.<br \/>\nIt also compacts (defragments) the memory by moving longer lived objects together, and even &#8220;promoting&#8221; them into different parts of the heap, called <em>generations<\/em>, to avoid checking their status too often.<\/p>\n<p>There is a bunch of memory being copied all the time without your program even realizing it. Since garbage collection is an operation that can happen at any time during the execution of your program, any pointer-related<br \/>\n(&#8220;unsafe&#8221;) operations must be done within a small scope, by telling the runtime to &#8220;pin&#8221; the objects using the <code>fixed<\/code> keyword. This prevents the GC from moving them, but only for a while.<\/p>\n<p>Using pointers and <code>unsafe<\/code> code in C# is not only less safe, but also not very idiomatic for managed languages in general. If coming from a C background, you may feel like at home with these constructs, but C# has a completely different philosophy: your job as a C# programmer should be to write reliable, readable and maintenable code, and only then think about squeezing a couple of CPU cycles for performance reasons. You can use pointers from time to time in small functions, doing some very specific, time-critical code. But even then it is your duty to <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/c2.com\/cgi\/wiki?ProfileBeforeOptimizing\">profile <strong>before<\/strong> making such optimizations<\/a>. Even the most experienced programmers often fail at predicting bottlenecks before profiling.<\/p>\n<p>Finally, regarding your actual code:<\/p>\n<ol>\n<li>\n<p>I don&#8217;t see why you think this:<\/p>\n<pre><code>int*[] pp = new int*[] {&amp;aaa, &amp;bbb, &amp;ccc};\n<\/code><\/pre>\n<p>would be any more performant than this:<\/p>\n<pre><code>int[] pp = new int[] {aaa, bbb, ccc};  \n<\/code><\/pre>\n<p>On a 32-bit machine, an <code>int<\/code> and a pointer are of the same size. On a 64-bit machine, a pointer is even bigger.<\/p>\n<\/li>\n<li>\n<p>Consider replacing these plain <code>int<\/code>s with a <code>class<\/code> of your own which will provide some context and additional functionality\/data to each of these values. Create a new question describing the actual problem you are trying to solve (you can also use <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/codereview.stackexchange.com\">Code Review<\/a> for such questions) and you will benefit from much better suggestions.<\/p>\n<\/li>\n<\/ol><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\"><\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved C# &#8211; How to Bypass Error cs0212 Cheaply for Programmers and Computers? <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] .NET runtime is a managed execution runtime which (among other things) provides garbage collection. .NET garbage collector (GC) not only manages the allocation and release of memory, but also transparently moves the objects around the &#8220;managed heap&#8221;, blocking the rest of your code while doing it. It also compacts (defragments) the memory by moving &#8230; <a title=\"[Solved] C# &#8211; How to Bypass Error cs0212 Cheaply for Programmers and Computers?\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-c-how-to-bypass-error-cs0212-cheaply-for-programmers-and-computers\/\" aria-label=\"More on [Solved] C# &#8211; How to Bypass Error cs0212 Cheaply for Programmers and Computers?\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[324,712],"class_list":["post-23046","post","type-post","status-publish","format-standard","hentry","category-solved","tag-c","tag-pointers"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] C# - How to Bypass Error cs0212 Cheaply for Programmers and Computers? - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-c-how-to-bypass-error-cs0212-cheaply-for-programmers-and-computers\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] C# - How to Bypass Error cs0212 Cheaply for Programmers and Computers? - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] .NET runtime is a managed execution runtime which (among other things) provides garbage collection. .NET garbage collector (GC) not only manages the allocation and release of memory, but also transparently moves the objects around the &#8220;managed heap&#8221;, blocking the rest of your code while doing it. It also compacts (defragments) the memory by moving ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-c-how-to-bypass-error-cs0212-cheaply-for-programmers-and-computers\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-11-23T05:23:26+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-c-how-to-bypass-error-cs0212-cheaply-for-programmers-and-computers\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-c-how-to-bypass-error-cs0212-cheaply-for-programmers-and-computers\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] C# &#8211; How to Bypass Error cs0212 Cheaply for Programmers and Computers?\",\"datePublished\":\"2022-11-23T05:23:26+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-c-how-to-bypass-error-cs0212-cheaply-for-programmers-and-computers\/\"},\"wordCount\":384,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"c++\",\"pointers\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-c-how-to-bypass-error-cs0212-cheaply-for-programmers-and-computers\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-c-how-to-bypass-error-cs0212-cheaply-for-programmers-and-computers\/\",\"name\":\"[Solved] C# - How to Bypass Error cs0212 Cheaply for Programmers and Computers? - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2022-11-23T05:23:26+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-c-how-to-bypass-error-cs0212-cheaply-for-programmers-and-computers\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-c-how-to-bypass-error-cs0212-cheaply-for-programmers-and-computers\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-c-how-to-bypass-error-cs0212-cheaply-for-programmers-and-computers\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] C# &#8211; How to Bypass Error cs0212 Cheaply for Programmers and Computers?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775193939\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775193939\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] C# - How to Bypass Error cs0212 Cheaply for Programmers and Computers? - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-c-how-to-bypass-error-cs0212-cheaply-for-programmers-and-computers\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] C# - How to Bypass Error cs0212 Cheaply for Programmers and Computers? - JassWeb","og_description":"[ad_1] .NET runtime is a managed execution runtime which (among other things) provides garbage collection. .NET garbage collector (GC) not only manages the allocation and release of memory, but also transparently moves the objects around the &#8220;managed heap&#8221;, blocking the rest of your code while doing it. It also compacts (defragments) the memory by moving ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-c-how-to-bypass-error-cs0212-cheaply-for-programmers-and-computers\/","og_site_name":"JassWeb","article_published_time":"2022-11-23T05:23:26+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-c-how-to-bypass-error-cs0212-cheaply-for-programmers-and-computers\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-c-how-to-bypass-error-cs0212-cheaply-for-programmers-and-computers\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] C# &#8211; How to Bypass Error cs0212 Cheaply for Programmers and Computers?","datePublished":"2022-11-23T05:23:26+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-c-how-to-bypass-error-cs0212-cheaply-for-programmers-and-computers\/"},"wordCount":384,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["c++","pointers"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-c-how-to-bypass-error-cs0212-cheaply-for-programmers-and-computers\/","url":"https:\/\/jassweb.com\/solved\/solved-c-how-to-bypass-error-cs0212-cheaply-for-programmers-and-computers\/","name":"[Solved] C# - How to Bypass Error cs0212 Cheaply for Programmers and Computers? - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-11-23T05:23:26+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-c-how-to-bypass-error-cs0212-cheaply-for-programmers-and-computers\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-c-how-to-bypass-error-cs0212-cheaply-for-programmers-and-computers\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-c-how-to-bypass-error-cs0212-cheaply-for-programmers-and-computers\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] C# &#8211; How to Bypass Error cs0212 Cheaply for Programmers and Computers?"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775193939","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775193939","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/23046","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=23046"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/23046\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=23046"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=23046"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=23046"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}