<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0"><channel><title><![CDATA[Bitesized Engineering]]></title><description><![CDATA[Engineering deep-dives for People in a hurry.]]></description><link>https://www.bitesizedengineering.com</link><image><url>https://substackcdn.com/image/fetch/$s_!-oQs!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F3b50eb3f-7dd2-424e-8665-02de0d089a71_1258x1280.png</url><title>Bitesized Engineering</title><link>https://www.bitesizedengineering.com</link></image><generator>Substack</generator><lastBuildDate>Thu, 30 Apr 2026 22:28:21 GMT</lastBuildDate><atom:link href="https://www.bitesizedengineering.com/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[Mihailo Joksimovic]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[bitesizedengineering@substack.com]]></webMaster><itunes:owner><itunes:email><![CDATA[bitesizedengineering@substack.com]]></itunes:email><itunes:name><![CDATA[Mihailo Joksimovic]]></itunes:name></itunes:owner><itunes:author><![CDATA[Mihailo Joksimovic]]></itunes:author><googleplay:owner><![CDATA[bitesizedengineering@substack.com]]></googleplay:owner><googleplay:email><![CDATA[bitesizedengineering@substack.com]]></googleplay:email><googleplay:author><![CDATA[Mihailo Joksimovic]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[Values and References - a deeper look into their behaviors]]></title><description><![CDATA[Chronicles of .NET runtime - Part 11]]></description><link>https://www.bitesizedengineering.com/p/values-and-references-a-deeper-look</link><guid isPermaLink="false">https://www.bitesizedengineering.com/p/values-and-references-a-deeper-look</guid><dc:creator><![CDATA[Mihailo Joksimovic]]></dc:creator><pubDate>Tue, 25 Apr 2023 06:35:02 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!l0Xf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82d811f0-d413-46c9-9a7f-e2f944500578_1600x4000.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hi there! &#128075;</p><p>Last time I discussed the topic of <a href="https://www.bitesizedengineering.com/p/who-here-do-values-and-references">who lives where</a>. And I mentioned that <strong>Values live on the Stack, whereas References live on the Managed Heap</strong>. All good. But since then, and since digging way deeper into the topic, I realized that <strong>this shouldn&#8217;t be the MAIN thing you care about</strong>. Should you know about it? Sure! But should it be the main thing you care about - no! <strong>The main point of consideration should be about the behaviors that they exhibit</strong>. And the behavior is determined based on how they are represented. So, let&#8217;s talk more about that.</p><p><em>If you&#8217;re a newcomer, this is article is a continuation of my Deep-dive into CLR (i.e. .NET&#8217;s runtime) series. If you haven&#8217;t seen any of the past articles - I&#8217;d recommend you <a href="https://www.bitesizedengineering.com/p/what-is-common-language-runtime-clr">start from beginning.</a></em></p><p>As usual, we start with the infographic first:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!l0Xf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82d811f0-d413-46c9-9a7f-e2f944500578_1600x4000.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!l0Xf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82d811f0-d413-46c9-9a7f-e2f944500578_1600x4000.png 424w, https://substackcdn.com/image/fetch/$s_!l0Xf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82d811f0-d413-46c9-9a7f-e2f944500578_1600x4000.png 848w, https://substackcdn.com/image/fetch/$s_!l0Xf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82d811f0-d413-46c9-9a7f-e2f944500578_1600x4000.png 1272w, https://substackcdn.com/image/fetch/$s_!l0Xf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82d811f0-d413-46c9-9a7f-e2f944500578_1600x4000.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!l0Xf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82d811f0-d413-46c9-9a7f-e2f944500578_1600x4000.png" width="1456" height="3640" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/82d811f0-d413-46c9-9a7f-e2f944500578_1600x4000.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:3640,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1103044,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!l0Xf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82d811f0-d413-46c9-9a7f-e2f944500578_1600x4000.png 424w, https://substackcdn.com/image/fetch/$s_!l0Xf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82d811f0-d413-46c9-9a7f-e2f944500578_1600x4000.png 848w, https://substackcdn.com/image/fetch/$s_!l0Xf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82d811f0-d413-46c9-9a7f-e2f944500578_1600x4000.png 1272w, https://substackcdn.com/image/fetch/$s_!l0Xf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82d811f0-d413-46c9-9a7f-e2f944500578_1600x4000.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Let me immediately quote Eric Lippert&#8217;s rant on References vs Value types:</p><blockquote><p><em>Almost every article I see that describes the difference between value types and reference types explains in (frequently incorrect) detail about what &#8220;the stack&#8221; is and how the major difference between value types and reference types is that value types go on the stack. I&#8217;m sure you can find dozens of examples by searching the web.</em></p><p><em>I find this characterization of a value type based on its implementation details rather than its observable characteristics to be both confusing and unfortunate. Surely the most relevant fact about value types is not the implementation detail of how they are allocated, but rather the by-design semantic meaning of &#8220;value type&#8221;, namely that they are always copied &#8220;by value&#8221;. If the relevant thing was their allocation details then we&#8217;d have called them &#8220;heap types&#8221; and &#8220;stack types&#8221;. But that&#8217;s not relevant most of the time. Most of the time the relevant thing is their copying and identity semantics.</em></p><p>Source: <a href="https://ericlippert.com/2009/04/27/the-stack-is-an-implementation-detail-part-one/">Eric Lipperts&#8217; Blog</a></p></blockquote><p>Given that, indeed, it gets hard to find valuable information, doubly so if you are looking for an image representation, I decided to create one. And here is the enlarged version:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!p2T9!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b01f9ca-97be-4495-900b-8d809979d948_1024x768.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!p2T9!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b01f9ca-97be-4495-900b-8d809979d948_1024x768.png 424w, https://substackcdn.com/image/fetch/$s_!p2T9!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b01f9ca-97be-4495-900b-8d809979d948_1024x768.png 848w, https://substackcdn.com/image/fetch/$s_!p2T9!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b01f9ca-97be-4495-900b-8d809979d948_1024x768.png 1272w, https://substackcdn.com/image/fetch/$s_!p2T9!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b01f9ca-97be-4495-900b-8d809979d948_1024x768.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!p2T9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b01f9ca-97be-4495-900b-8d809979d948_1024x768.png" width="522" height="391.5" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7b01f9ca-97be-4495-900b-8d809979d948_1024x768.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:768,&quot;width&quot;:1024,&quot;resizeWidth&quot;:522,&quot;bytes&quot;:57445,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!p2T9!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b01f9ca-97be-4495-900b-8d809979d948_1024x768.png 424w, https://substackcdn.com/image/fetch/$s_!p2T9!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b01f9ca-97be-4495-900b-8d809979d948_1024x768.png 848w, https://substackcdn.com/image/fetch/$s_!p2T9!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b01f9ca-97be-4495-900b-8d809979d948_1024x768.png 1272w, https://substackcdn.com/image/fetch/$s_!p2T9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b01f9ca-97be-4495-900b-8d809979d948_1024x768.png 1456w" sizes="100vw"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>In order to explain the behavior, you need to understand WHY is that behavior happening in the first place</strong>. And having an image should help.</p><p>Think of both Value and Reference types as Boxes. That&#8217;s it. Boxes. And there&#8217;s content inside of those boxes. What the exact content is, I&#8217;ll explain on the example of trying to store integer &#8220;42&#8221; inside the box.</p><div class="pullquote"><p><strong>Value Types store actual value inside of them. As in - actual bits that make up the information that you are trying to store.</strong></p></div><p>In case of &#8220;42&#8221;, if we stored it inside the variable called &#8220;valueVar&#8221;, that variable would literally contain the bits that make up 42 (i.e. 000&#8230;00101010). I guess that&#8217;s simple enough to digest, right?</p><p>When it comes to Reference Types, the story is a bit different.</p><div class="pullquote"><p><strong>Reference Types store the address where a value can be found. And that address points to the Managed Heap.</strong></p></div><p>In case of &#8220;42&#8221;, if you were to store it in the variable called &#8220;referenceVar&#8221;, you&#8217;d effectively be storing the &#8220;42&#8221; (i.e. 000&#8230;00101010) somewhere on the Managed Heap, and the actual 64-bit address where the value could be found would be stored inside &#8220;referenceVar&#8221;.</p><pre><code>valueVar = 42; // valueVar now contains 101010 (i.e. 42 in binary)

referenceVar = 42; // referenceVar now contains 64-bit address where 42 can be found (e.g. 010110101010011...01010)</code></pre><p>Why that matters? Well it matters because of the behaviors they exhibit. And these behaviors are fundamentally different and in order to understand them, we need to quickly remind ourselves of how CPUs work.</p><p><strong>CPU by itself has no knowledge of Value / Reference types</strong>. Hell, not only does it NOT have the knowledge, but it doesn&#8217;t care either. <strong>When it comes to CPU, all it does is moves the bits back &amp; forth between RAM &amp; registers</strong>. That&#8217;s it.</p><p><strong>So what really happens with Value and Reference types is that, whatever is inside of them, will be copied back &amp; forth</strong>. If it&#8217;s an actual value - the value itself gets copied. If it&#8217;s a reference - well, the memory address gets copied. But ultimately, CPU doesn&#8217;t care what it is! It&#8217;s just bits!</p><p>Let&#8217;s take a very simple example of passing both value &amp; reference type to some function and then changing it:</p><pre><code>valueVar = 42;

referenceVar = (42); // I added brackets to denote that it's a "reference" to 42 being stored elsewhere

changeVar(variable):
  variable = 88;</code></pre><p>Can you blind-guess what happens with each of these? <strong>From point of view of CPU, it just copies whatever is inside the variable and it doesn&#8217;t care about WHAT it represents</strong>.</p><p>So, in case of valueVar, the bits that represent 42 get copied to another location on the Stack. And then those bits get updated to bits that represent 88. But did it affect the original &#8220;42&#8221;? Of course not - you changed the bits of the copy of the value!</p><p>In case of referenceVar, though, what gets passed to the function is the ADDRESS. Address where &#8220;42&#8221; is stored. And once you change it to 88, what you are effectively doing is storing &#8220;88&#8221; to the address where 42 was initially stored. As you can imagine, this effectively &#8220;overwrites&#8221; the value. But I think &#8220;overwrite&#8221; is a really shitty term. You are passing an ADDRESS, a WAYPOINT of a sort, and then saying to store something else to that ADDRESS. Whatever was there will be overwritten by new value. <strong>So you are not really &#8220;overwriting the variable&#8221;, but you are effectively changing the content of whatever is stored at the address that the variable holds</strong>. Simple! :)</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.bitesizedengineering.com/subscribe?"><span>Subscribe now</span></a></p><p>But, let&#8217;s for the sake of fun, say that you want to update the content of a referenceVar. So you don&#8217;t want to update the content at the address that referenceVar holds, but you rather want to update the variable itself. So, how do you do it? Well, turns out that that&#8217;s exactly what &#8220;ref&#8221; keyword in C# does - it passes the address of the referenceVar (i.e. a reference TO THE VARIABLE), so any changes to it would, effectively, overwrite the content of the variable itself.</p><p>Finally, <strong>let&#8217;s talk about Boxing and Unboxing. They are just ways to convert between Value and Reference types</strong>. And that&#8217;s actually pretty much it. Boxing a value type means - take the value from variable, store it somewhere on the heap, and store the address back to the variable, effectively making it &#8220;reference variable&#8221;. Unboxing is vice-versa - it takes the value from the heap, and stores its bits into a variable, effectively making it a &#8220;value type&#8221;.</p><p>Here&#8217;s a very simple C# code that shows that:</p><pre><code>int valueVar = 42; // Value Type

object referenceVar = valueVar; // Boxes the "valueVar" by copying 42 to somewhere on the Heap, and then stores the address in referenceVar

int anotherValueVar = (int) referenceVar; // Does the exact opposite by "unboxing"</code></pre><p>For the sheer fun of it, here&#8217;s the IL code for the code above:</p><pre><code>IL_0000: nop
IL_0001: ldc.i4.s 42
IL_0003: stloc.0
IL_0004: ldloc.0
IL_0005: box [System.Runtime]System.Int32
IL_000a: stloc.1
IL_000b: ldloc.1
IL_000c: unbox.any [System.Runtime]System.Int32
IL_0011: stloc.2
IL_0012: ret</code></pre><p>Finally, here&#8217;s an amusing piece of code to amuse you:</p><pre><code>int fooBar = 42;

Console.WriteLine("Value is: {}", fooBar)</code></pre><p>Can you guess why it has to box the fooBar before printing it? :)</p><p>Finally, again for the sheer fun of it, I asked ChatGPT to summarize Values and References as if I was a five years old, and here&#8217;s what came up as a result:</p><blockquote><p><em>Okay, let's imagine you have a toy car, and you want to give it to your friend to play with.</em></p><p><em>Now, there are two ways you can do this:</em></p><ol><li><p><em>You can give your friend the exact same toy car that you have. In this case, your friend has a copy of the car, but it's still a separate car from yours. This is like a "value type."</em></p></li><li><p><em>You can show your friend your toy car and say "Here, play with this car!" In this case, your friend is playing with the same car you have, because you're referring to the car that you already have. This is like a "reference type."</em></p></li></ol><p><em>In programming, value types are like a copy of the toy car, while reference types are like the original toy car that you're referring to. When you use a value type, you're creating a new thing that's separate from the original thing. When you use a reference type, you're talking about the same thing that already exists.</em></p><p>Source: ChatGPT</p></blockquote><p>And that&#8217;d be all for today. I hope you enjoyed it and if you did - do consider subscribing if you haven&#8217;t already :)</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.bitesizedengineering.com/subscribe?"><span>Subscribe now</span></a></p><p>Thanks for reading!</p><div><hr></div><p>Other articles from the CLR series:</p><ul><li><p><a href="https://www.bitesizedengineering.com/p/assemblys-shameless-metadata-marketing">Assembly's Shameless Metadata Marketing</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/managed-vs-unmanaged-code-part-1">Managed vs Unmanaged Code - Part 1</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/managed-vs-unmanaged-code-part-2">Managed vs Unmanaged Code - Part 2</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/common-language-infrastructure-runtime">Common Language Infrastructure, Runtime, Type System and other C-s</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/who-here-do-values-and-references">Where do Values and References live at?</a></p></li></ul>]]></content:encoded></item><item><title><![CDATA[Where do Values and References live at?]]></title><description><![CDATA[Chronicles of .NET runtime - Part 10]]></description><link>https://www.bitesizedengineering.com/p/who-here-do-values-and-references</link><guid isPermaLink="false">https://www.bitesizedengineering.com/p/who-here-do-values-and-references</guid><dc:creator><![CDATA[Mihailo Joksimovic]]></dc:creator><pubDate>Thu, 20 Apr 2023 14:01:52 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!Rad6!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbec97d2b-8b56-41a7-8278-d21d250dcac9_1600x4000.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hi! &#128075;</p><p>I finally decided to move away from all the meta-topics and C-stuff. As promised, I&#8217;m going to start exploring the .NET memory allocation and common data types.</p><p><em>If you&#8217;re a newcomer, this is article is a continuation of my Deep-dive into CLR (i.e. .NET&#8217;s runtime) series. If you haven&#8217;t seen any of the past articles - I&#8217;d recommend you <a href="https://www.bitesizedengineering.com/p/what-is-common-language-runtime-clr">start from beginning.</a></em></p><p>It&#8217;s really worth pointing out that if you&#8217;re not that familiar with Stacks and Heaps, I&#8217;d suggest reading <a href="https://www.bitesizedengineering.com/p/heaps-and-stacks-explained-like-youre-five">this article</a> to get a sense of it first. Additionally, you might benefit from going through the <a href="https://www.bitesizedengineering.com/p/c-and-memory-allocation-for-people">C++ and Memory Management series</a>, which covers the basic concepts of memory works on a lower level.</p><p>As usual, the infographic goes first and then the more detailed text will be below:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Rad6!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbec97d2b-8b56-41a7-8278-d21d250dcac9_1600x4000.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Rad6!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbec97d2b-8b56-41a7-8278-d21d250dcac9_1600x4000.png 424w, https://substackcdn.com/image/fetch/$s_!Rad6!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbec97d2b-8b56-41a7-8278-d21d250dcac9_1600x4000.png 848w, https://substackcdn.com/image/fetch/$s_!Rad6!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbec97d2b-8b56-41a7-8278-d21d250dcac9_1600x4000.png 1272w, https://substackcdn.com/image/fetch/$s_!Rad6!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbec97d2b-8b56-41a7-8278-d21d250dcac9_1600x4000.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Rad6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbec97d2b-8b56-41a7-8278-d21d250dcac9_1600x4000.png" width="1456" height="3640" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bec97d2b-8b56-41a7-8278-d21d250dcac9_1600x4000.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:3640,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1062420,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Rad6!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbec97d2b-8b56-41a7-8278-d21d250dcac9_1600x4000.png 424w, https://substackcdn.com/image/fetch/$s_!Rad6!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbec97d2b-8b56-41a7-8278-d21d250dcac9_1600x4000.png 848w, https://substackcdn.com/image/fetch/$s_!Rad6!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbec97d2b-8b56-41a7-8278-d21d250dcac9_1600x4000.png 1272w, https://substackcdn.com/image/fetch/$s_!Rad6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbec97d2b-8b56-41a7-8278-d21d250dcac9_1600x4000.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>For those in a real hurry, I guess it&#8217;s enough to remember that, <strong>when it comes to .NET and CLR, you really have two main data types - Values and References</strong>. Depending on who you ask, they might claim that &#8220;primitives&#8221; are a third type, but I&#8217;d just categorize them under Value Types. <strong>Value Types live on the Stack, and Reference Types are located on the Managed Heap</strong>. And, for those who want to continue with their day - that&#8217;s probably enough info.</p><p>For those eager to learn more - stay with me :) As we&#8217;ve discussed in the past articles, <strong>when it comes to Managed Code, it&#8217;s really the runtime engine (CLR) that determines where your data is stored</strong>. This is really interesting in comparison to C and C++, where you have the full control over the storage. As in, if you use the keyword &#8220;new&#8221; or &#8220;malloc&#8221;, your data will go to the (unmanaged) heap. On the other hand, if you just declare the variable, without &#8220;new&#8221; (or &#8220;malloc&#8221;), your data will be stored on the thread&#8217;s stack. So technically it&#8217;s up to you to decide where you want to place your data; and it&#8217;s also up to you to maintain the garbage left on the Heap.</p><p>In contrast, Managed Code has to manage the memory for you. And the language engineers seem to have thought that it&#8217;s a bit too much of a burden to bother you with, so they made a simple decision - <strong>any data type that inherits from System.ValueType (e.g. structs, enums, primitives like integers, floats, etc.) will be stored on the Stack. End of story</strong>. And this is probably something that would confuse a C++ engineer &#8212; the keyword &#8220;new&#8221; doesn&#8217;t allocate bits from the heap, but rather allocates the memory; on the stack; at least for Value Types.</p><p>When it comes to References, the story is different. Anything that is of &#8220;Reference&#8221; data type will ALWAYS go to the Heap. That includes Classes, Interfaces, Arrays, Strings, etc. Pretty much anything that could grow larger than couple of bytes is likely to go to Heap. </p><p>In a nutshell, and this is really amusing, <strong>when it comes to .NET and CLR - it&#8217;s the Data Type that determines where your data lives</strong>. And I think that&#8217;s just interesting :)</p><p>As usual, the devil really is in the details here. One with a sharp eye might notice and ask about Value Types inside Reference Types. For example - what happens with an Integer defined inside the Class? Does it live on the Stack or the Heap? And as you could imagine - answer is - obviously it lives on the Heap, because it&#8217;s part of the Reference Type. But these details and inner-workings is something that we will be discussing in more depth in future articles.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.bitesizedengineering.com/subscribe?"><span>Subscribe now</span></a></p><p>Before I close this off, I want to make honorable mention of &#8220;box&#8221; and &#8220;unbox&#8221;, which are some common concepts that many have heard of, but not everyone is comfortable elaborating. I&#8217;m in that group, but I&#8217;ll try to give a short intro - <strong>boxing variables referes to the process of converting them from Value to Reference type; or, as you could imagine, moving them from Stack to Heap. Unboxing, on the other hand, is kind of an opposite operation - it takes the Value Type from the Heap and stores it on the Stack</strong>. But as I&#8217;ve learned, there are one too many people pointing out that there&#8217;s much more than that, and this is really something that I&#8217;ll be exploring and writing about over next articles.</p><p>Finally, one last remark - there&#8217;s much more to be said about Values and References. One of their properties is where they are stored, but as many have pointed out - this is really more of an implementation detail. Still, I find this to be a valuable information, but in the next article I will dig into what they really are supposed to be.</p><p>Thanks for reading!</p><div><hr></div><p>Other articles from the CLR series:</p><ul><li><p><a href="https://www.bitesizedengineering.com/p/asymmetric-cryptography-public-keys">Asymmetric Cryptography, Public keys and Strongly-named assemblies</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/assemblys-shameless-metadata-marketing">Assembly's Shameless Metadata Marketing</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/managed-vs-unmanaged-code-part-1">Managed vs Unmanaged Code - Part 1</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/managed-vs-unmanaged-code-part-2">Managed vs Unmanaged Code - Part 2</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/common-language-infrastructure-runtime">Common Language Infrastructure, Runtime, Type System and other C-s</a></p></li></ul>]]></content:encoded></item><item><title><![CDATA[Common Language Infrastructure, Runtime, Type System and other C-s]]></title><description><![CDATA[Chronicles of .NET runtime - Part 9]]></description><link>https://www.bitesizedengineering.com/p/common-language-infrastructure-runtime</link><guid isPermaLink="false">https://www.bitesizedengineering.com/p/common-language-infrastructure-runtime</guid><dc:creator><![CDATA[Mihailo Joksimovic]]></dc:creator><pubDate>Sun, 16 Apr 2023 04:02:51 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!Py9h!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d53da7d-4deb-4f38-a814-9f023146b714_1600x4000.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>I finally did it :) Honestly, If you&#8217;ve been following the CLR series from the beginning, you likely learned that I struggled to figure out all the C-s that are being thrown around. CLI, CIL, CLR, CTS, CLS &#8230; out of nowhere VES shows up &#8230; hell! It&#8217;s one C too many!</p><p>Well, I think I finally have it nailed down, so let&#8217;s talk about it now.</p><p><em>If you are a newcomer</em>, <em>this article is a continuation of my Deep-dive into CLR (i.e. .NET&#8217;s runtime) series. If you haven&#8217;t read any of the past articles - I&#8217;d recommend you <a href="https://www.bitesizedengineering.com/p/what-is-common-language-runtime-clr">start from the beginning.</a></em></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Py9h!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d53da7d-4deb-4f38-a814-9f023146b714_1600x4000.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Py9h!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d53da7d-4deb-4f38-a814-9f023146b714_1600x4000.png 424w, https://substackcdn.com/image/fetch/$s_!Py9h!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d53da7d-4deb-4f38-a814-9f023146b714_1600x4000.png 848w, https://substackcdn.com/image/fetch/$s_!Py9h!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d53da7d-4deb-4f38-a814-9f023146b714_1600x4000.png 1272w, https://substackcdn.com/image/fetch/$s_!Py9h!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d53da7d-4deb-4f38-a814-9f023146b714_1600x4000.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Py9h!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d53da7d-4deb-4f38-a814-9f023146b714_1600x4000.png" width="1456" height="3640" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6d53da7d-4deb-4f38-a814-9f023146b714_1600x4000.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:3640,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1094300,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Py9h!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d53da7d-4deb-4f38-a814-9f023146b714_1600x4000.png 424w, https://substackcdn.com/image/fetch/$s_!Py9h!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d53da7d-4deb-4f38-a814-9f023146b714_1600x4000.png 848w, https://substackcdn.com/image/fetch/$s_!Py9h!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d53da7d-4deb-4f38-a814-9f023146b714_1600x4000.png 1272w, https://substackcdn.com/image/fetch/$s_!Py9h!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d53da7d-4deb-4f38-a814-9f023146b714_1600x4000.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>I hope you found that useful? If not - well, at least I really felt relief once I managed to put all of it into an infographic. Woohoo!</p><p>Before jumping into the WHAT&#8217;s and HOW&#8217;s, let me just quickly summarize how we got here in the first place. <strong>It all started with the idea of exploring the CLR</strong>. Which, to tell you the truth, I was clueless that existed as a concept at all. I knew about C# and .NET, and I was aware it wasn&#8217;t compiled to native code, but that was all.</p><p>As luck would have it, my manager started talking about CLR and SQL Server, and how the two could be integrated (which, if you didn&#8217;t know, is this amazing thing that allows you to run your .NET code back-to-back with SQL Server&#8217;s Query Engine). This triggered me to go and learn what CLR is at all. And that&#8217;s how this whole series about <a href="https://www.bitesizedengineering.com/p/what-is-common-language-runtime-clr">&#8220;Deep dive into CLR&#8221;</a> started.</p><p>Now here&#8217;s the funny thing - <strong>there doesn&#8217;t seem to be a clear info on anything about the CLR anywhere on Internet</strong>. Well, at least not clear enough for somebody whose just trying to learn about it. <strong>All the online docs make perfect sense if you know WHAT it is, but if you&#8217;re a newcomer - good luck :)</strong> So I kept reading about CLR (there&#8217;s this great book called &#8220;CLR via C#&#8221; by Jeffrey Richter) but I also kept finding references to CLR being implementation of CLI.</p><p>Thing is - I had no clue what the CLI is. And to make it even funnier - there&#8217;s also CIL, which stands for Common Intermediate Language. People might occasionally call it IL or MSIL - Intermediate Language and Microsoft&#8217;s Intermediate Language. Perfect for newcomers!</p><p>To cut the long story short - <strong>I kept searching for a diagram, or anything that would show me the connection between CLR, CLI, CIL, CTS, CLS, etc. But I found nothing</strong>. Nil. Void. Which eventually led me to the idea of creating one:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!BeoW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa2242712-b9eb-4447-8c52-ba45f1611a17_1600x900.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!BeoW!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa2242712-b9eb-4447-8c52-ba45f1611a17_1600x900.png 424w, https://substackcdn.com/image/fetch/$s_!BeoW!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa2242712-b9eb-4447-8c52-ba45f1611a17_1600x900.png 848w, https://substackcdn.com/image/fetch/$s_!BeoW!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa2242712-b9eb-4447-8c52-ba45f1611a17_1600x900.png 1272w, https://substackcdn.com/image/fetch/$s_!BeoW!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa2242712-b9eb-4447-8c52-ba45f1611a17_1600x900.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!BeoW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa2242712-b9eb-4447-8c52-ba45f1611a17_1600x900.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a2242712-b9eb-4447-8c52-ba45f1611a17_1600x900.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:169729,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!BeoW!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa2242712-b9eb-4447-8c52-ba45f1611a17_1600x900.png 424w, https://substackcdn.com/image/fetch/$s_!BeoW!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa2242712-b9eb-4447-8c52-ba45f1611a17_1600x900.png 848w, https://substackcdn.com/image/fetch/$s_!BeoW!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa2242712-b9eb-4447-8c52-ba45f1611a17_1600x900.png 1272w, https://substackcdn.com/image/fetch/$s_!BeoW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa2242712-b9eb-4447-8c52-ba45f1611a17_1600x900.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Now this honestly makes me happy because I can finally have a mental image of what is what and what is a subset of what, which is something I&#8217;ve been trying to figure out for a while. Let&#8217;s start from top and progress towards the bottom.</p><p><strong>Common Language Infrastructure (CLI) is an openly available standard, commonly referred to as ECMA-335 standard</strong>. You can find it <a href="https://www.ecma-international.org/publications-and-standards/standards/ecma-335/">here</a>. It&#8217;s a 500+ page long PDF which describes absolutely every possible thing you could imagine. And somebody told me that <strong>&#8220;first 100 pages should be a necessary read for every .NET developer&#8221;</strong>. </p><p>CLI describes the platform. The unique environment that makes it possible to execute multiple languages on. And yes, that means - C#, VB.NET, F#, Managed C++ (commonly called C++/CLI) and even Python (through IronPython), PHP (through PeachPie) and others. So CLI is a top-level idea which, among other things, defines the following:</p><ol><li><p>The language, commonly called <strong>Common Intermediate Language (CIL)</strong>, but occasionally referred to as Microsoft&#8217;s Intermediate Language (MSIL). I wrote extensively about it in <a href="https://www.bitesizedengineering.com/p/what-is-common-language-runtime-clr">this article</a>.</p></li><li><p>Type System, commonly called <strong>Common Type System (CTS)</strong>, which basically argues how you make some meaning out of your bits. It distinguishes two types of data - value types and references, and builds further from there. Any language that wants to conform to CLI has to take into account the CTS definitions.</p></li><li><p>VM itself, called <strong>Virtual Execution System (VES)</strong>, which actually executes the Intermediate Language. Interestingly enough, CLR (Common Language Runtime) is just one implementation of VES.</p></li><li><p>And finally - <strong>Metadata</strong>, which is that thing that everybody loves, right? The data about the data; or the description of data. Meta data. It&#8217;s actually really cool and CLI defines TONS of parameters needed in order to give your data an actual meaning which VES further uses to execute your bytecode. It also, among other things, dictates how the CLI code can be injected into EXE files, making them executable just like it was a native code.</p></li></ol><p>Reasonable question to ask would be &#8212; WHY? Why would anyone do this in the first place? And I find the actual definition from <a href="https://www.ecma-international.org/wp-content/uploads/ECMA-335_6th_edition_june_2012.pdf">ECMA-335 PDF</a> to be a perfect answer here:</p><p><em><strong>The CTS is about integration between languages: using another language&#8217;s objects as if they were one&#8217;s own.</strong> </em></p><p><em><strong>The objective of the CLI is to make it easier to write components and applications in any language</strong>. It does this by defining a standard set of types, by making all components fully self&#2;describing, and by providing a high performance common execution environment. This ensures that all CLI-compliant system services and components will be accessible to all CLI-aware languages and tools. In addition, this simplifies deployment of components and applications that use them, all in a way that allows compilers and other tools to leverage the high performance execution environment. The CTS covers, at a high level, the concepts and interactions that make all of this possible.</em></p><p>I think that puts the intent just perfectly - make it possible to have multiple languages, that don&#8217;t even have to share the syntax, but which do conform to the same rules - rules of CLI. <strong>This way you can, say, write majority of code in C#, but write some specific expressions in F# and just reuse them back in C#</strong>. Given that it all compiles to same language, the problem simply boils down to the syntax itself :)</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ltId!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff71b9368-8c8b-4312-b6da-b5034cf28a1e_1600x900.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ltId!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff71b9368-8c8b-4312-b6da-b5034cf28a1e_1600x900.png 424w, https://substackcdn.com/image/fetch/$s_!ltId!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff71b9368-8c8b-4312-b6da-b5034cf28a1e_1600x900.png 848w, https://substackcdn.com/image/fetch/$s_!ltId!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff71b9368-8c8b-4312-b6da-b5034cf28a1e_1600x900.png 1272w, https://substackcdn.com/image/fetch/$s_!ltId!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff71b9368-8c8b-4312-b6da-b5034cf28a1e_1600x900.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ltId!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff71b9368-8c8b-4312-b6da-b5034cf28a1e_1600x900.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f71b9368-8c8b-4312-b6da-b5034cf28a1e_1600x900.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:194288,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ltId!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff71b9368-8c8b-4312-b6da-b5034cf28a1e_1600x900.png 424w, https://substackcdn.com/image/fetch/$s_!ltId!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff71b9368-8c8b-4312-b6da-b5034cf28a1e_1600x900.png 848w, https://substackcdn.com/image/fetch/$s_!ltId!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff71b9368-8c8b-4312-b6da-b5034cf28a1e_1600x900.png 1272w, https://substackcdn.com/image/fetch/$s_!ltId!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff71b9368-8c8b-4312-b6da-b5034cf28a1e_1600x900.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>And that&#8217;d be about it for this article :) And to tell you the truth - this really takes a huge burden of my back as I&#8217;ve been really struggling to put all of this into a perspective. The fact that I finally did do it really makes me happy. And I hope you found it useful! :)</p><p>If you enjoyed this article - be mindful that I try to post twice a week. So if you haven&#8217;t subscribed already, now&#8217;d be a good time to do so:</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.bitesizedengineering.com/subscribe?"><span>Subscribe now</span></a></p><p>I&#8217;d also appreciate if you share it with your colleagues:</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/p/common-language-infrastructure-runtime?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.bitesizedengineering.com/p/common-language-infrastructure-runtime?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p>Thanks for reading!</p><div><hr></div><ul><li><p><a href="https://www.bitesizedengineering.com/p/what-is-assemblys-manifest">What is Assembly's Manifest?</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/weakly-and-strongly-named-assemblies">Weakly and Strongly-named Assemblies</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/asymmetric-cryptography-public-keys">Asymmetric Cryptography, Public keys and Strongly-named assemblies</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/assemblys-shameless-metadata-marketing">Assembly's Shameless Metadata Marketing</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/managed-vs-unmanaged-code-part-1">Managed vs Unmanaged Code - Part 1</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/managed-vs-unmanaged-code-part-2">Managed vs Unmanaged Code - Part 2</a></p></li></ul><p></p>]]></content:encoded></item><item><title><![CDATA[Managed vs Unmanaged Code - Part 2]]></title><description><![CDATA[Chronicles of .NET runtime - Part 8]]></description><link>https://www.bitesizedengineering.com/p/managed-vs-unmanaged-code-part-2</link><guid isPermaLink="false">https://www.bitesizedengineering.com/p/managed-vs-unmanaged-code-part-2</guid><dc:creator><![CDATA[Mihailo Joksimovic]]></dc:creator><pubDate>Thu, 13 Apr 2023 04:03:00 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!LZNi!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3dc32cb-36bc-4da2-a6f5-eb4cbfc01e7f_1600x4000.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hi!</p><p><a href="https://www.bitesizedengineering.com/p/managed-vs-unmanaged-code-part-1">Last time</a> I opened up a story on Managed and Unmanaged code and I mentioned that I believed it was a nice intro before jumping into Stacks and Heaps. I also mentioned that along the way I realized that what I thought was &#8220;Managed Code&#8221; was not in check with what it really was. This article is supposed to be the ultimate explanation and clarification on WHAT it really is.</p><p><em>If you are a newcomer</em>, <em>this article is a continuation of my Deep-dive into CLR (i.e. .NET&#8217;s runtime) series. If you haven&#8217;t read any of the past articles - I&#8217;d recommend you <a href="https://www.bitesizedengineering.com/p/what-is-common-language-runtime-clr">start from the beginning.</a></em></p><p>As per usual, we go with infographic first and then we&#8217;ll discuss the inner details afterwards:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!LZNi!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3dc32cb-36bc-4da2-a6f5-eb4cbfc01e7f_1600x4000.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!LZNi!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3dc32cb-36bc-4da2-a6f5-eb4cbfc01e7f_1600x4000.png 424w, https://substackcdn.com/image/fetch/$s_!LZNi!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3dc32cb-36bc-4da2-a6f5-eb4cbfc01e7f_1600x4000.png 848w, https://substackcdn.com/image/fetch/$s_!LZNi!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3dc32cb-36bc-4da2-a6f5-eb4cbfc01e7f_1600x4000.png 1272w, https://substackcdn.com/image/fetch/$s_!LZNi!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3dc32cb-36bc-4da2-a6f5-eb4cbfc01e7f_1600x4000.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!LZNi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3dc32cb-36bc-4da2-a6f5-eb4cbfc01e7f_1600x4000.png" width="1456" height="3640" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e3dc32cb-36bc-4da2-a6f5-eb4cbfc01e7f_1600x4000.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:3640,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1003252,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!LZNi!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3dc32cb-36bc-4da2-a6f5-eb4cbfc01e7f_1600x4000.png 424w, https://substackcdn.com/image/fetch/$s_!LZNi!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3dc32cb-36bc-4da2-a6f5-eb4cbfc01e7f_1600x4000.png 848w, https://substackcdn.com/image/fetch/$s_!LZNi!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3dc32cb-36bc-4da2-a6f5-eb4cbfc01e7f_1600x4000.png 1272w, https://substackcdn.com/image/fetch/$s_!LZNi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3dc32cb-36bc-4da2-a6f5-eb4cbfc01e7f_1600x4000.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Okay, cool. I hope you found that useful :)</p><p>Here&#8217;s the deal - as I mentioned in previous article - I was under impression that &#8220;Managed Code&#8221; and &#8220;Managed Languages&#8221; refer to languages that have Garbage Collection. Then I learned it&#8217;s more than that - it refers to languages that have a &#8220;manager&#8221; that manages the stuff for you. But WHAT kind of stuff? And WHO is this manager? Too many questions started popping up to the point that I thought about giving up this whole idea altogether and skipping right to memory management itself.</p><p>Thankfully, I persisted. And I eventually learned that the term &#8220;Managed Code&#8221; got coined by Microsoft. And not just that, but I eventually started putting together the whole puzzle with Common Language Infrastructure (CLI), Common Intermediate Language (CIL), Common Language Runtime (CLR), Common Language Specification (CLS), Virtual Execution System (VES), etc. I won&#8217;t bother you much with it as there will be a separate dedicated article that will cover all of these. But I&#8217;ll just give you the essence that might be useful for the topic.</p><p>&#8220;Managed Code&#8221; refers to the code that compiles to something called &#8220;Intermediate Language&#8221;, which is just a fancy way of saying &#8220;a code that is not native machine code&#8221;. That&#8217;s what Intermediate Language is - a middle-man. And it&#8217;s officially called Common Intermediate Language (CIL; not to be confused with CLI).</p><p>To give you an example - C# code compiles to Intermediate Language. So does VB.NET. So does a version of C++ that is usually called C++/CLI or Managed C++. And I wrote a lot about Intermediate Language in <a href="https://www.bitesizedengineering.com/p/what-is-common-language-runtime-clr">previous articles</a>, so do make sure to check them out if you&#8217;ve never seen how it looks like.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.bitesizedengineering.com/subscribe?"><span>Subscribe now</span></a></p><p>But how does the code move from Intermediate Language to Native CPU instructions? This is yet another thing defined by Common Language Infrastructure - runtime engine. CLI defines a thing called Virtual Execution System (VES) which describes how you go from Intermediate Language to Native architecture where your program is executing. And this is where it becomes funny - CLR (Common Language Runtime) is JUST ONE of the concrete implementations of VES. But there are others as well! There&#8217;s Mono, there&#8217;s .net nanoFramework, and I guess there are others as well. But CLR is rather popular one because it&#8217;s what usually executes your .NET code :)</p><p>So let&#8217;s try and answer the &#8220;What is Managed Code?&#8221; question again - Managed Code is any code that conforms to Common Language Infrastructure standard and that compiles to Intermediate Language. After that, the runtime engine (e.g. CLR) takes over and ensures that your code converts into actual CPU instructions, which is a process known as JIT Compilation (Just-in-Time Compilation). But more about that in future!</p><p>By now I&#8217;m sure that you&#8217;ve figured that calling Java, or any other languge a &#8220;Managed one&#8221; is wrong? Unless you have a compiler that turns Java into Common Intermediate Language, then it&#8217;s not &#8220;Managed&#8221;. Simple as that, I guess? :)</p><p>And that pretty much concludes today&#8217;s story. I&#8217;m going to dedicate a separate article to the whole &#8220;CLI, CIL, CLR, CTS, CLS, VES, etc.&#8221; chaos, but until then, I hope this thing here gives you a bit of clarity :) Until then, if you haven&#8217;t subscribed already, now&#8217;s probably a good time to do so:</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.bitesizedengineering.com/subscribe?"><span>Subscribe now</span></a></p><p>I&#8217;d also appreciate if you share this article with your network:</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/p/managed-vs-unmanaged-code-part-2?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.bitesizedengineering.com/p/managed-vs-unmanaged-code-part-2?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p>Thanks for reading!</p><div><hr></div><p>Other articles from the CLR series:</p><ul><li><p><a href="https://www.bitesizedengineering.com/p/what-is-a-net-assembly">What is a .NET assembly?</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/what-is-assemblys-manifest">What is Assembly's Manifest?</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/weakly-and-strongly-named-assemblies">Weakly and Strongly-named Assemblies</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/asymmetric-cryptography-public-keys">Asymmetric Cryptography, Public keys and Strongly-named assemblies</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/assemblys-shameless-metadata-marketing">Assembly's Shameless Metadata Marketing</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/managed-vs-unmanaged-code-part-1">Managed vs Unmanaged Code - Part 1</a></p></li></ul>]]></content:encoded></item><item><title><![CDATA[Managed vs Unmanaged Code - Part 1]]></title><description><![CDATA[Chronicles of .NET runtime - Part 7]]></description><link>https://www.bitesizedengineering.com/p/managed-vs-unmanaged-code-part-1</link><guid isPermaLink="false">https://www.bitesizedengineering.com/p/managed-vs-unmanaged-code-part-1</guid><dc:creator><![CDATA[Mihailo Joksimovic]]></dc:creator><pubDate>Sat, 08 Apr 2023 07:47:07 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!HXld!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F131ab592-57a4-466c-a829-a4d7ba137906_1600x4000.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>This one was, in all honesty, eating me alive. My plan was to start writing about Memory Management, Stacks and Heaps in .NET, but then I figured it&#8217;d probably make sense to open up with a backstory of Managed (and Unmanaged) languages. Should have been a simple one; almost. What I thought would be a night or two job, turned into a week-long journey of trying to unfuddle the shit out of WHAT EXACTLY does Managed vs Unmanaged mean. Well, I think I finally have an answer ready, but before I tell you the answer, I first want to share how I got there. And this article is about that.</p><p><em>If you are a newcomer</em>, <em>this article is a continuation of my Deep-dive into CLR (i.e. .NET&#8217;s runtime) series. If you haven&#8217;t read any of the past articles - I&#8217;d recommend you <a href="https://www.bitesizedengineering.com/p/what-is-common-language-runtime-clr">start from the beginning.</a></em></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!HXld!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F131ab592-57a4-466c-a829-a4d7ba137906_1600x4000.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!HXld!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F131ab592-57a4-466c-a829-a4d7ba137906_1600x4000.png 424w, https://substackcdn.com/image/fetch/$s_!HXld!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F131ab592-57a4-466c-a829-a4d7ba137906_1600x4000.png 848w, https://substackcdn.com/image/fetch/$s_!HXld!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F131ab592-57a4-466c-a829-a4d7ba137906_1600x4000.png 1272w, https://substackcdn.com/image/fetch/$s_!HXld!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F131ab592-57a4-466c-a829-a4d7ba137906_1600x4000.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!HXld!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F131ab592-57a4-466c-a829-a4d7ba137906_1600x4000.png" width="1456" height="3640" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/131ab592-57a4-466c-a829-a4d7ba137906_1600x4000.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:3640,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1120224,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!HXld!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F131ab592-57a4-466c-a829-a4d7ba137906_1600x4000.png 424w, https://substackcdn.com/image/fetch/$s_!HXld!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F131ab592-57a4-466c-a829-a4d7ba137906_1600x4000.png 848w, https://substackcdn.com/image/fetch/$s_!HXld!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F131ab592-57a4-466c-a829-a4d7ba137906_1600x4000.png 1272w, https://substackcdn.com/image/fetch/$s_!HXld!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F131ab592-57a4-466c-a829-a4d7ba137906_1600x4000.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>I hope you enjoyed the infographic. But I have to disappoint you now - it&#8217;s incorrect :) Well, to be more precise - mostly incorrect. Ouch.</p><p>Here&#8217;s the deal - I used to think that Managed vs Unmanaged refers to the fact whether the language has Garbage Collector or not. Which kind of made sense and I&#8217;m sure at least some of you share these same beliefs.</p><p>Then I started investigating and looking around and I figured that it actually refers to MORE than the Garbage Collection. It refers to languages that have a &#8220;Manager&#8221; that takes care of your shit. Oh, did I say &#8220;shit&#8221;? I meant - resources. Logistics, as some would say. And in a way, it was true. Managed Languages DO have some kind of manager that manages stuff for you.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.bitesizedengineering.com/subscribe?"><span>Subscribe now</span></a></p><p>Next, I started thinking about the proper analogy. Because one thing I love about my bitesized articles is that I always try coming up with a simple analogy that would engrave the concept in your brain. What came to mind was &#8220;singers&#8221;. They could be &#8220;freelancers&#8221; and manage all of their gigs on their own, or they could hire a manager to take care of their crap while they focus on their art. And the analogy made sense because you could point blank ask &#8220;so, what&#8217;s better?&#8221; and the answer would be the most disliked answer ever produced - &#8220;it depends&#8221;. And it really DOES depend. Being a freelance artist gives you a freedom, possibly more money, more control, etc. But it comes with some costs, right? You have to manage way more crap than someone with a dedicated manager. You could really bounce back &amp; forth and I&#8217;m sure you could generate tons of pros &amp; cons for both.</p><p>The analogy and this whole graphic made a lot of sense. But something didn&#8217;t really click. So, C# is managed language, VB.net is managed language, Java is managed language, Python, Ruby and PHP would likely fit under the &#8220;managed languages&#8221; umbrella as well. On the other hand - C and C++ are unmanaged languages. They give you a full access to memory and whatnot. Well, yeah, just like freelance artists - they allow you to do whatever the heck you want. It all fits. Almost.</p><p>Then I started producing some questions that I couldn&#8217;t really find a proper answer to - &#8220;is Rust a managed language&#8221;? &#8220;What about Go?&#8221;. The answers weren&#8217;t really clear to be honest.</p><p>I came around a Quora post that claims that &#8220;Unmanaged Languages&#8221; compile to Native code, whereas Managed ones compile to Bytecode. That makes sense. So that means that Rust and Go are also Unmanaged, right? Almost.</p><p>Rust, I guess you could say fits the &#8220;Unmanaged&#8221; category. It compiles to machine friendly bits, it doesn&#8217;t have garbage collection, you are allowed to do whatever the heck you want &#8230; it all fits. Perfect. But Go fucked me up :) Go, even though I never really used it, claims that it manages your resources for you. In a way. And it has Garbage Collector. But it also compiles to native code. What the actual fuck? What the fuck are you, Go? Are you Managed or Unmanaged for hell&#8217;s sake?</p><p>The fact that I couldn&#8217;t answer this question really meant one thing - I didn&#8217;t have a complete picture of what this all means. And like I said at the beginning - it was eating me alive. What&#8217;s more, I just couldn&#8217;t proceed with Bitesized Articles before I answered this question. I HAD TO answer this question.</p><p>I eventually came to learn that &#8220;Managed Code&#8221; was a term that was coined by no one else but my current employer - Microsoft :) The earliest reference I could find dates back to April 2003. Yes, that&#8217;s 20 years ago! And it was a reference that &#8220;explains&#8221; the idea behind the term, so I guess the term itself was coined even earlier. I&#8217;m guessing that it originated with the whole CLR and CLI thing, but I yet have to check this out.</p><p>Managed Code refers to the code that compiles to Common Intermediate Language (CIL), often referred to as Microsoft&#8217;s Intermediate Language (MSIL) or just Intermediate Language (IL). And yes, it&#8217;s that damn thing that I keep ranting about from the beginning of <a href="https://www.bitesizedengineering.com/p/what-is-common-language-runtime-clr">this series</a>. <strong>Managed Code is a code that compiles to Intermediate Language and gets executed by Common Language Runtime (CLR)</strong>. That&#8217;s it.  That&#8217;s the whole point. Nothing to do with Garbage Collection or whatever. No. It&#8217;s all about Common Language Runtime (CLR) and Intermediate Language. And yes, that explains the meaning behind &#8220;Managed C++&#8221; - it&#8217;s C++ that compiles into Intermediate Language and can be executed by CLR.</p><p>What this further means is that the graphic from above is barely wrong :) It&#8217;s wrong because it missed the point of &#8220;Managed&#8221;. And that&#8217;s why I named this one &#8220;part 1&#8221;. In &#8220;Part 2&#8221; I will do the proper honors and explain this exactly as it is.</p><p>Until then, if you enjoyed this, you might also want to subscribe :)</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.bitesizedengineering.com/subscribe?"><span>Subscribe now</span></a></p><p>I&#8217;d also appreciate if you share this with your colleagues:</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/p/managed-vs-unmanaged-code-part-1?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.bitesizedengineering.com/p/managed-vs-unmanaged-code-part-1?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p>Thanks a lot for reading!</p><div><hr></div><p>Other articles from the CLR series:</p><ul><li><p><a href="https://www.bitesizedengineering.com/p/what-is-common-language-runtime-clr">What is Common Language Runtime (CLR) and why should I learn about it?</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/what-is-a-net-assembly">What is a .NET assembly?</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/what-is-assemblys-manifest">What is Assembly's Manifest?</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/weakly-and-strongly-named-assemblies">Weakly and Strongly-named Assemblies</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/asymmetric-cryptography-public-keys">Asymmetric Cryptography, Public keys and Strongly-named assemblies</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/assemblys-shameless-metadata-marketing">Assembly's Shameless Metadata Marketing</a></p></li></ul><p></p>]]></content:encoded></item><item><title><![CDATA[Assembly's Shameless Metadata Marketing]]></title><description><![CDATA[Chronicles of .NET runtime - Part 6]]></description><link>https://www.bitesizedengineering.com/p/assemblys-shameless-metadata-marketing</link><guid isPermaLink="false">https://www.bitesizedengineering.com/p/assemblys-shameless-metadata-marketing</guid><dc:creator><![CDATA[Mihailo Joksimovic]]></dc:creator><pubDate>Sat, 01 Apr 2023 07:31:18 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!0-Ye!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73d6f93d-2cc7-407d-8362-a722f6fee407_1600x4000.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hi there! &#128075;</p><p>It&#8217;s a new day and new opportunity to learn something interesting about .NET and CLR :)</p><p><em>For those just joining this train</em>, <em>This is a continuation of my Deep-dive into CLR (i.e. .NET&#8217;s runtime) series. If you haven&#8217;t seen any of the past articles - I&#8217;d recommend you <a href="https://www.bitesizedengineering.com/p/what-is-common-language-runtime-clr">start from the beginning.</a></em></p><p><em><strong>NOTE: This article is a bit longer and might get cut off by your email client. I suggest opening it either in Substack app or in <a href="https://www.bitesizedengineering.com/p/assemblys-shameless-metadata-marketing">your web browser</a>.</strong></em></p><p>Today I want to talk about something that is deemed to be boring. Well hell, I myself avoided reading about it because I thought it&#8217;s boring as crap. And to tell you the truth - <strong>I was, in fact, right. It is boring as crap</strong>. Metadata. Metadata tables. <strong>Anything that has &#8220;meta&#8221; in it is usually something that you deal with only if you&#8217;re forced to, right</strong>? :) Nobody likes meta (no pun intended).</p><p>To tell you the truth - I never really planned on writing this article. Seriously. Because I didn&#8217;t care about it and I&#8217;m sure you don&#8217;t care either. But something changed. And what changed is that, all of a sudden, it all clicked in my head. FUCK. Holy FUCK. That Metadata thing &#8230; That metadata thing is actually REALLY COOL! Like FUCKING AWESOME. <strong>It&#8217;s like Assembly itself WANTS you to inspect it</strong>. Look into it. Explore it! Plus, it tells you ALL about its behavior, its constraints, its memory requirements &#8230; you name it and there&#8217;s likely a metadata about it! <strong>It&#8217;s a GOLD MINE if you want to learn stuff about DLL or EXE in front of you</strong>!</p><p>Before we jump into the details, let&#8217;s start with Infographic first and then I&#8217;ll share more:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!0-Ye!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73d6f93d-2cc7-407d-8362-a722f6fee407_1600x4000.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!0-Ye!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73d6f93d-2cc7-407d-8362-a722f6fee407_1600x4000.png 424w, https://substackcdn.com/image/fetch/$s_!0-Ye!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73d6f93d-2cc7-407d-8362-a722f6fee407_1600x4000.png 848w, https://substackcdn.com/image/fetch/$s_!0-Ye!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73d6f93d-2cc7-407d-8362-a722f6fee407_1600x4000.png 1272w, https://substackcdn.com/image/fetch/$s_!0-Ye!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73d6f93d-2cc7-407d-8362-a722f6fee407_1600x4000.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!0-Ye!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73d6f93d-2cc7-407d-8362-a722f6fee407_1600x4000.png" width="1456" height="3640" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/73d6f93d-2cc7-407d-8362-a722f6fee407_1600x4000.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:3640,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1007454,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!0-Ye!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73d6f93d-2cc7-407d-8362-a722f6fee407_1600x4000.png 424w, https://substackcdn.com/image/fetch/$s_!0-Ye!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73d6f93d-2cc7-407d-8362-a722f6fee407_1600x4000.png 848w, https://substackcdn.com/image/fetch/$s_!0-Ye!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73d6f93d-2cc7-407d-8362-a722f6fee407_1600x4000.png 1272w, https://substackcdn.com/image/fetch/$s_!0-Ye!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73d6f93d-2cc7-407d-8362-a722f6fee407_1600x4000.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>A&#8217;ight, I hope that was a bit more amusing than a dry thought of Metadata? :)</p><p>Now before we embark on the journey of this post, I really want to emphasize that ILDASM.exe (Intermediate Language Disassembler) is really a tool that you want to have handy. It&#8217;s surely lying somewhere in your .NET folder so just go and search for it (btw, I use a tool called &#8220;Everything&#8221; which is this blazing fast indexer that just rocks):</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!rvVN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc03940e2-7970-47bb-b853-e7c6065f1c36_1317x351.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!rvVN!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc03940e2-7970-47bb-b853-e7c6065f1c36_1317x351.png 424w, https://substackcdn.com/image/fetch/$s_!rvVN!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc03940e2-7970-47bb-b853-e7c6065f1c36_1317x351.png 848w, https://substackcdn.com/image/fetch/$s_!rvVN!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc03940e2-7970-47bb-b853-e7c6065f1c36_1317x351.png 1272w, https://substackcdn.com/image/fetch/$s_!rvVN!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc03940e2-7970-47bb-b853-e7c6065f1c36_1317x351.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!rvVN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc03940e2-7970-47bb-b853-e7c6065f1c36_1317x351.png" width="1317" height="351" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c03940e2-7970-47bb-b853-e7c6065f1c36_1317x351.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:351,&quot;width&quot;:1317,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:48550,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!rvVN!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc03940e2-7970-47bb-b853-e7c6065f1c36_1317x351.png 424w, https://substackcdn.com/image/fetch/$s_!rvVN!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc03940e2-7970-47bb-b853-e7c6065f1c36_1317x351.png 848w, https://substackcdn.com/image/fetch/$s_!rvVN!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc03940e2-7970-47bb-b853-e7c6065f1c36_1317x351.png 1272w, https://substackcdn.com/image/fetch/$s_!rvVN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc03940e2-7970-47bb-b853-e7c6065f1c36_1317x351.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Next, I want to look into MSCorLib.dll, which, from my very modest search, seems to stand for Microsoft Common Object Runtime Library (there&#8217;s some history behind WHY is that, and the WHY seems to be that before it was named .NET, it was meant as improvement of COM). MSCorLib.dll is a core runtime library for .NET and what I want to do is see what it&#8217;s Manifest can tell me about it:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!y1ur!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fe8a128-b2b1-472e-8ea5-b0b48f082c01_699x675.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!y1ur!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fe8a128-b2b1-472e-8ea5-b0b48f082c01_699x675.png 424w, https://substackcdn.com/image/fetch/$s_!y1ur!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fe8a128-b2b1-472e-8ea5-b0b48f082c01_699x675.png 848w, https://substackcdn.com/image/fetch/$s_!y1ur!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fe8a128-b2b1-472e-8ea5-b0b48f082c01_699x675.png 1272w, https://substackcdn.com/image/fetch/$s_!y1ur!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fe8a128-b2b1-472e-8ea5-b0b48f082c01_699x675.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!y1ur!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fe8a128-b2b1-472e-8ea5-b0b48f082c01_699x675.png" width="699" height="675" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8fe8a128-b2b1-472e-8ea5-b0b48f082c01_699x675.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:675,&quot;width&quot;:699,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:16471,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!y1ur!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fe8a128-b2b1-472e-8ea5-b0b48f082c01_699x675.png 424w, https://substackcdn.com/image/fetch/$s_!y1ur!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fe8a128-b2b1-472e-8ea5-b0b48f082c01_699x675.png 848w, https://substackcdn.com/image/fetch/$s_!y1ur!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fe8a128-b2b1-472e-8ea5-b0b48f082c01_699x675.png 1272w, https://substackcdn.com/image/fetch/$s_!y1ur!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fe8a128-b2b1-472e-8ea5-b0b48f082c01_699x675.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ejn5!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38cc7144-2d3d-49b1-b4cd-02d5322c73c8_702x701.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ejn5!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38cc7144-2d3d-49b1-b4cd-02d5322c73c8_702x701.png 424w, https://substackcdn.com/image/fetch/$s_!ejn5!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38cc7144-2d3d-49b1-b4cd-02d5322c73c8_702x701.png 848w, https://substackcdn.com/image/fetch/$s_!ejn5!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38cc7144-2d3d-49b1-b4cd-02d5322c73c8_702x701.png 1272w, https://substackcdn.com/image/fetch/$s_!ejn5!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38cc7144-2d3d-49b1-b4cd-02d5322c73c8_702x701.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ejn5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38cc7144-2d3d-49b1-b4cd-02d5322c73c8_702x701.png" width="702" height="701" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/38cc7144-2d3d-49b1-b4cd-02d5322c73c8_702x701.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:701,&quot;width&quot;:702,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:34731,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ejn5!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38cc7144-2d3d-49b1-b4cd-02d5322c73c8_702x701.png 424w, https://substackcdn.com/image/fetch/$s_!ejn5!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38cc7144-2d3d-49b1-b4cd-02d5322c73c8_702x701.png 848w, https://substackcdn.com/image/fetch/$s_!ejn5!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38cc7144-2d3d-49b1-b4cd-02d5322c73c8_702x701.png 1272w, https://substackcdn.com/image/fetch/$s_!ejn5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38cc7144-2d3d-49b1-b4cd-02d5322c73c8_702x701.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!_6fP!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ed03ece-d63c-4044-84fd-012a378f2350_1913x1038.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!_6fP!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ed03ece-d63c-4044-84fd-012a378f2350_1913x1038.png 424w, https://substackcdn.com/image/fetch/$s_!_6fP!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ed03ece-d63c-4044-84fd-012a378f2350_1913x1038.png 848w, https://substackcdn.com/image/fetch/$s_!_6fP!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ed03ece-d63c-4044-84fd-012a378f2350_1913x1038.png 1272w, https://substackcdn.com/image/fetch/$s_!_6fP!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ed03ece-d63c-4044-84fd-012a378f2350_1913x1038.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!_6fP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ed03ece-d63c-4044-84fd-012a378f2350_1913x1038.png" width="1456" height="790" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2ed03ece-d63c-4044-84fd-012a378f2350_1913x1038.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:790,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:35700,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!_6fP!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ed03ece-d63c-4044-84fd-012a378f2350_1913x1038.png 424w, https://substackcdn.com/image/fetch/$s_!_6fP!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ed03ece-d63c-4044-84fd-012a378f2350_1913x1038.png 848w, https://substackcdn.com/image/fetch/$s_!_6fP!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ed03ece-d63c-4044-84fd-012a378f2350_1913x1038.png 1272w, https://substackcdn.com/image/fetch/$s_!_6fP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ed03ece-d63c-4044-84fd-012a378f2350_1913x1038.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>That&#8217;s quite a biggie right there :) And what I actually find amusing is that, <strong>in certain scenarios, your DLL&#8217;s metadata overhead could be way bigger than the actual code that it contains</strong> :) DLL&#8217;s and EXEs are really chatty!</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.bitesizedengineering.com/subscribe?"><span>Subscribe now</span></a></p><p>So, in a nutshell, what are Metadata Tables? Well, just like with any meta data, <strong>their purpose is to DESCRIBE the Assembly</strong> (DLL or EXE; I guess I&#8217;m becoming boring by repeating this all the time?). And to tell you the truth, it&#8217;s not just meant for you, but it&#8217;s actually meant for CLR (Common Language Runtime - <a href="https://www.bitesizedengineering.com/p/what-is-common-language-runtime-clr">the runtime engine of .NET</a>). It tells CLR which objects are inside, which are required to be imported, how much memory is needed, etc. </p><p>If you really stop and think about it - <strong>I guess there&#8217;s simply no other way to have an architecture-agnostic binaries without Metadata</strong>. Like, you either compile the binaries for specific architecture (e.g. Windows and x64) or you have some way of communicating HOW to go from &#8220;intermediate language&#8221; to a native CPU opcodes. And the latter is communicated by Metadata. I never checked it but I&#8217;d guess Java and it&#8217;s JVM works the same way.</p><p>So what I&#8217;m going to do now is paste some random excerpts of Metadata from the gigantic file I&#8217;ve shown you above. Then I&#8217;m going to discuss each of.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!7Tyz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4941a3f0-ba05-4277-ab22-52fbf0025912_949x572.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!7Tyz!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4941a3f0-ba05-4277-ab22-52fbf0025912_949x572.png 424w, https://substackcdn.com/image/fetch/$s_!7Tyz!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4941a3f0-ba05-4277-ab22-52fbf0025912_949x572.png 848w, https://substackcdn.com/image/fetch/$s_!7Tyz!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4941a3f0-ba05-4277-ab22-52fbf0025912_949x572.png 1272w, https://substackcdn.com/image/fetch/$s_!7Tyz!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4941a3f0-ba05-4277-ab22-52fbf0025912_949x572.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!7Tyz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4941a3f0-ba05-4277-ab22-52fbf0025912_949x572.png" width="949" height="572" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4941a3f0-ba05-4277-ab22-52fbf0025912_949x572.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:572,&quot;width&quot;:949,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:18986,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!7Tyz!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4941a3f0-ba05-4277-ab22-52fbf0025912_949x572.png 424w, https://substackcdn.com/image/fetch/$s_!7Tyz!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4941a3f0-ba05-4277-ab22-52fbf0025912_949x572.png 848w, https://substackcdn.com/image/fetch/$s_!7Tyz!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4941a3f0-ba05-4277-ab22-52fbf0025912_949x572.png 1272w, https://substackcdn.com/image/fetch/$s_!7Tyz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4941a3f0-ba05-4277-ab22-52fbf0025912_949x572.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>So what we see here are two TypeDefs, shorthand for Type Definition. As you could imagine, this means that these are these two types that exist inside this assembly - EmptyArray and FXAssembly.</p><p>Inside each of those TypeDefs, we see Fields and Methods, which I guess goes without saying that it represents the fields and methods inside those types.</p><p>&#8220;Flags&#8221; represent the info for JIT and CLR on how to interpret these Types and Methods. For example, &#8220;[Private]&#8221; flag above the &#8220;.cctor&#8221; method means that Constructor (.cctor is a shorthand for constructor) is Private.</p><p>There is a total of 2992 types defined inside this assembly and the last one is the one shown below:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!AmQG!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F178b472d-ca01-4ada-9c25-9841a8117b84_851x256.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!AmQG!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F178b472d-ca01-4ada-9c25-9841a8117b84_851x256.png 424w, https://substackcdn.com/image/fetch/$s_!AmQG!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F178b472d-ca01-4ada-9c25-9841a8117b84_851x256.png 848w, https://substackcdn.com/image/fetch/$s_!AmQG!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F178b472d-ca01-4ada-9c25-9841a8117b84_851x256.png 1272w, https://substackcdn.com/image/fetch/$s_!AmQG!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F178b472d-ca01-4ada-9c25-9841a8117b84_851x256.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!AmQG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F178b472d-ca01-4ada-9c25-9841a8117b84_851x256.png" width="851" height="256" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/178b472d-ca01-4ada-9c25-9841a8117b84_851x256.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:256,&quot;width&quot;:851,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:9154,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!AmQG!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F178b472d-ca01-4ada-9c25-9841a8117b84_851x256.png 424w, https://substackcdn.com/image/fetch/$s_!AmQG!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F178b472d-ca01-4ada-9c25-9841a8117b84_851x256.png 848w, https://substackcdn.com/image/fetch/$s_!AmQG!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F178b472d-ca01-4ada-9c25-9841a8117b84_851x256.png 1272w, https://substackcdn.com/image/fetch/$s_!AmQG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F178b472d-ca01-4ada-9c25-9841a8117b84_851x256.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!xxRP!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe492ec2a-818f-4dba-999c-86c64bca4bbd_851x256.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!xxRP!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe492ec2a-818f-4dba-999c-86c64bca4bbd_851x256.png 424w, https://substackcdn.com/image/fetch/$s_!xxRP!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe492ec2a-818f-4dba-999c-86c64bca4bbd_851x256.png 848w, https://substackcdn.com/image/fetch/$s_!xxRP!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe492ec2a-818f-4dba-999c-86c64bca4bbd_851x256.png 1272w, https://substackcdn.com/image/fetch/$s_!xxRP!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe492ec2a-818f-4dba-999c-86c64bca4bbd_851x256.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!xxRP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe492ec2a-818f-4dba-999c-86c64bca4bbd_851x256.png" width="851" height="256" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e492ec2a-818f-4dba-999c-86c64bca4bbd_851x256.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:256,&quot;width&quot;:851,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!xxRP!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe492ec2a-818f-4dba-999c-86c64bca4bbd_851x256.png 424w, https://substackcdn.com/image/fetch/$s_!xxRP!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe492ec2a-818f-4dba-999c-86c64bca4bbd_851x256.png 848w, https://substackcdn.com/image/fetch/$s_!xxRP!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe492ec2a-818f-4dba-999c-86c64bca4bbd_851x256.png 1272w, https://substackcdn.com/image/fetch/$s_!xxRP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe492ec2a-818f-4dba-999c-86c64bca4bbd_851x256.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Aside from TypeDefs, what we also see if we keep scrolling this gigantic piece of DLL, is the following:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Sih8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77ea5e87-5795-4e3b-9a41-7e165f2faa32_445x359.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Sih8!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77ea5e87-5795-4e3b-9a41-7e165f2faa32_445x359.png 424w, https://substackcdn.com/image/fetch/$s_!Sih8!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77ea5e87-5795-4e3b-9a41-7e165f2faa32_445x359.png 848w, https://substackcdn.com/image/fetch/$s_!Sih8!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77ea5e87-5795-4e3b-9a41-7e165f2faa32_445x359.png 1272w, https://substackcdn.com/image/fetch/$s_!Sih8!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77ea5e87-5795-4e3b-9a41-7e165f2faa32_445x359.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Sih8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77ea5e87-5795-4e3b-9a41-7e165f2faa32_445x359.png" width="445" height="359" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/77ea5e87-5795-4e3b-9a41-7e165f2faa32_445x359.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:359,&quot;width&quot;:445,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:6992,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Sih8!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77ea5e87-5795-4e3b-9a41-7e165f2faa32_445x359.png 424w, https://substackcdn.com/image/fetch/$s_!Sih8!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77ea5e87-5795-4e3b-9a41-7e165f2faa32_445x359.png 848w, https://substackcdn.com/image/fetch/$s_!Sih8!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77ea5e87-5795-4e3b-9a41-7e165f2faa32_445x359.png 1272w, https://substackcdn.com/image/fetch/$s_!Sih8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77ea5e87-5795-4e3b-9a41-7e165f2faa32_445x359.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Bunch of ModuleRefs (16 in total). As you could imagine, these are external assemblies that are needed in order for this assembly to function properly. </p><p>Then we have this:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!IycS!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff369199b-673e-4e14-90e5-f4b65cebeacb_1019x548.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!IycS!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff369199b-673e-4e14-90e5-f4b65cebeacb_1019x548.png 424w, https://substackcdn.com/image/fetch/$s_!IycS!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff369199b-673e-4e14-90e5-f4b65cebeacb_1019x548.png 848w, https://substackcdn.com/image/fetch/$s_!IycS!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff369199b-673e-4e14-90e5-f4b65cebeacb_1019x548.png 1272w, https://substackcdn.com/image/fetch/$s_!IycS!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff369199b-673e-4e14-90e5-f4b65cebeacb_1019x548.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!IycS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff369199b-673e-4e14-90e5-f4b65cebeacb_1019x548.png" width="1019" height="548" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f369199b-673e-4e14-90e5-f4b65cebeacb_1019x548.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:548,&quot;width&quot;:1019,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:16828,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!IycS!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff369199b-673e-4e14-90e5-f4b65cebeacb_1019x548.png 424w, https://substackcdn.com/image/fetch/$s_!IycS!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff369199b-673e-4e14-90e5-f4b65cebeacb_1019x548.png 848w, https://substackcdn.com/image/fetch/$s_!IycS!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff369199b-673e-4e14-90e5-f4b65cebeacb_1019x548.png 1272w, https://substackcdn.com/image/fetch/$s_!IycS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff369199b-673e-4e14-90e5-f4b65cebeacb_1019x548.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Bunch of attributes about the assembly itself. Some of these you could actually override (e.g. Company Name, Version, etc.).</p><p>Then we have FIVE additional files that are inside this assembly:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!OFja!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d75ee14-910e-43c0-8774-f5069fcdb339_710x588.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!OFja!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d75ee14-910e-43c0-8774-f5069fcdb339_710x588.png 424w, https://substackcdn.com/image/fetch/$s_!OFja!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d75ee14-910e-43c0-8774-f5069fcdb339_710x588.png 848w, https://substackcdn.com/image/fetch/$s_!OFja!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d75ee14-910e-43c0-8774-f5069fcdb339_710x588.png 1272w, https://substackcdn.com/image/fetch/$s_!OFja!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d75ee14-910e-43c0-8774-f5069fcdb339_710x588.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!OFja!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d75ee14-910e-43c0-8774-f5069fcdb339_710x588.png" width="710" height="588" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7d75ee14-910e-43c0-8774-f5069fcdb339_710x588.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:588,&quot;width&quot;:710,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:14916,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!OFja!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d75ee14-910e-43c0-8774-f5069fcdb339_710x588.png 424w, https://substackcdn.com/image/fetch/$s_!OFja!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d75ee14-910e-43c0-8774-f5069fcdb339_710x588.png 848w, https://substackcdn.com/image/fetch/$s_!OFja!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d75ee14-910e-43c0-8774-f5069fcdb339_710x588.png 1272w, https://substackcdn.com/image/fetch/$s_!OFja!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d75ee14-910e-43c0-8774-f5069fcdb339_710x588.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>If you remember the article on <a href="https://www.bitesizedengineering.com/p/what-is-assemblys-manifest">Assembly Manifest</a>, <strong>I mentioned that you might have more than one file packed inside Assembly</strong>. In this case, there are five .nlp files which, to tell you the truth, I have no clue what they are :)</p><p>Finally, last one interesting to me was this one:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!0Q5M!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13b7ed3e-80da-4c36-9d8d-c89512eed7bb_458x129.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!0Q5M!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13b7ed3e-80da-4c36-9d8d-c89512eed7bb_458x129.png 424w, https://substackcdn.com/image/fetch/$s_!0Q5M!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13b7ed3e-80da-4c36-9d8d-c89512eed7bb_458x129.png 848w, https://substackcdn.com/image/fetch/$s_!0Q5M!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13b7ed3e-80da-4c36-9d8d-c89512eed7bb_458x129.png 1272w, https://substackcdn.com/image/fetch/$s_!0Q5M!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13b7ed3e-80da-4c36-9d8d-c89512eed7bb_458x129.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!0Q5M!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13b7ed3e-80da-4c36-9d8d-c89512eed7bb_458x129.png" width="458" height="129" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/13b7ed3e-80da-4c36-9d8d-c89512eed7bb_458x129.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:129,&quot;width&quot;:458,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2927,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!0Q5M!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13b7ed3e-80da-4c36-9d8d-c89512eed7bb_458x129.png 424w, https://substackcdn.com/image/fetch/$s_!0Q5M!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13b7ed3e-80da-4c36-9d8d-c89512eed7bb_458x129.png 848w, https://substackcdn.com/image/fetch/$s_!0Q5M!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13b7ed3e-80da-4c36-9d8d-c89512eed7bb_458x129.png 1272w, https://substackcdn.com/image/fetch/$s_!0Q5M!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13b7ed3e-80da-4c36-9d8d-c89512eed7bb_458x129.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>All the Strings that show up in your code will be stored under &#8220;User Strings&#8221; metadata table (btw, &#8220;L&#8221; stands for &#8220;Long&#8221; meaning that each character takes 2-bytes).</p><p>From my research, there appears to be around 40+ Metadata Tables, but sadly, the only resource where I could find this list was a &#8220;CLR via C#&#8221; book :/ I&#8217;m sure there&#8217;s a full list somewhere as part of CIL specification, but I haven&#8217;t found it yet. Once I do, I will update this article.</p><p>And there you have it :) <strong>I think knowing what your assembly holds is really valuable as you can do all kinds of cool stuff with it</strong> (e.g. analyze the dependency tree or ensure that code isn&#8217;t doing anything it&#8217;s not supposed to be doing). </p><p>This also marks the end of me talking about assemblies only (so far I dedicated past three articles on it; you can find them below). Next article will shift focus towards memory management, Stacks and Heaps and differences between Managed and Unmanaged languages.</p><p>Until then, if you haven&#8217;t already, I&#8217;d appreciate if you subscribe. I tend to publish these deep-dives at least twice a week and I make sure they are fun to read:</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.bitesizedengineering.com/subscribe?"><span>Subscribe now</span></a></p><p>You may also help this article reach wider audience by sharing it with your network (which I&#8217;d also appreciate!):</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/p/assemblys-shameless-metadata-marketing?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.bitesizedengineering.com/p/assemblys-shameless-metadata-marketing?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p>Thanks for reading and see you next time!</p><div><hr></div><p>Other articles from the CLR series:</p><ul><li><p><a href="https://www.bitesizedengineering.com/p/asymmetric-cryptography-public-keys">Asymmetric Cryptography, Public keys and Strongly-named assemblies</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/what-is-common-language-runtime-clr">What is Common Language Runtime (CLR) and why should I learn about it?</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/what-is-a-net-assembly">What is a .NET assembly?</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/what-is-assemblys-manifest">What is Assembly's Manifest?</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/weakly-and-strongly-named-assemblies">Weakly and Strongly-named Assemblies</a></p></li></ul>]]></content:encoded></item><item><title><![CDATA[Asymmetric Cryptography, Public keys and Strongly-named assemblies]]></title><description><![CDATA[Chronicles of .NET runtime - Part 5]]></description><link>https://www.bitesizedengineering.com/p/asymmetric-cryptography-public-keys</link><guid isPermaLink="false">https://www.bitesizedengineering.com/p/asymmetric-cryptography-public-keys</guid><dc:creator><![CDATA[Mihailo Joksimovic]]></dc:creator><pubDate>Mon, 27 Mar 2023 04:05:53 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!uNXh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a4461dd-fba4-426b-9bbf-0befdd92a01a_1600x4000.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hi there! &#128075;</p><p><em>This is a continuation of my Deep-dive into CLR (i.e. .NET&#8217;s runtime) series. If you missed the previous article on <a href="https://www.bitesizedengineering.com/p/weakly-and-strongly-named-assemblies">Weakly and Strongly-named assemblies</a>, I&#8217;d recommend checking that one first. If you haven&#8217;t seen any of the past articles - I&#8217;d recommend you <a href="https://www.bitesizedengineering.com/p/what-is-common-language-runtime-clr">start from beginning.</a> Finally, if you&#8217;re here just for asymmetric cryptography - enjoy :)</em> </p><p>Last time I mentioned that <strong>Strongly-named assemblies are ones that are digitally signed by the owner</strong>. I also promised to share more details on what that means at all. And this is what I want to do now :)</p><p>As usual - infographic goes first and more details below:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!uNXh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a4461dd-fba4-426b-9bbf-0befdd92a01a_1600x4000.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!uNXh!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a4461dd-fba4-426b-9bbf-0befdd92a01a_1600x4000.png 424w, https://substackcdn.com/image/fetch/$s_!uNXh!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a4461dd-fba4-426b-9bbf-0befdd92a01a_1600x4000.png 848w, https://substackcdn.com/image/fetch/$s_!uNXh!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a4461dd-fba4-426b-9bbf-0befdd92a01a_1600x4000.png 1272w, https://substackcdn.com/image/fetch/$s_!uNXh!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a4461dd-fba4-426b-9bbf-0befdd92a01a_1600x4000.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!uNXh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a4461dd-fba4-426b-9bbf-0befdd92a01a_1600x4000.png" width="1456" height="3640" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6a4461dd-fba4-426b-9bbf-0befdd92a01a_1600x4000.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:3640,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:909475,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!uNXh!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a4461dd-fba4-426b-9bbf-0befdd92a01a_1600x4000.png 424w, https://substackcdn.com/image/fetch/$s_!uNXh!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a4461dd-fba4-426b-9bbf-0befdd92a01a_1600x4000.png 848w, https://substackcdn.com/image/fetch/$s_!uNXh!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a4461dd-fba4-426b-9bbf-0befdd92a01a_1600x4000.png 1272w, https://substackcdn.com/image/fetch/$s_!uNXh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a4461dd-fba4-426b-9bbf-0befdd92a01a_1600x4000.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>I hope that wasn&#8217;t too much to digest? If it is - please let me know and I&#8217;ll do more graphics to break this down even further. </p><p>The thing with asymmetric cryptography is that it might look spooky and confusing at first. And it most certainly felt so for me when I encountered it for the first time, some 5-6 years ago. But just like everything else - it&#8217;s REALLY simple. And I&#8217;ll make sure to explain it properly.</p><p>Let&#8217;s first start with symmetric cryptography. <strong>In symmetric crypto, what you have is ONE key (think of it as a password if you want) that can both LOCK and UNLOCK the data</strong>. It&#8217;s literally like a physical key - <strong>you can put the data into a box, lock it and whoever wants to unlock that box would need to have the exact same key</strong>. This also means that if your key gets stolen you&#8217;d have to change the whole lock. Some of the popular symmetric crypto algorithms are AES, DES, 3DES, etc. (do note that DES is now deemed insecure).</p><p>Generally speaking, symmetric cryptography and symmetric ciphers are great and really fast, but <strong>the problem is the distribution of the key</strong>. In order to use encrypted communication, you would first have to exchange the key with the party you are trying to talk to, but how do you do that over an insecure network, like Internet? Hint: you don&#8217;t.</p><p>This is something that Asymmetric Cryptography aims to solve. <strong>Instead of having ONE key that you&#8217;d have to exchange, somebody came up with an awesome idea - why not have TWO keys</strong>? They&#8217;d work in pairs (i.e. one wouldn&#8217;t make sense without the other) but <strong>one would have to be kept Private and another one should be publicly shared</strong> (e.g. you can put it in your email signature). They were named Private and Public keys respectively.</p><p>So the way it works is really simple. <strong>Think of it as having a lock that can be locked with ANY of the two (either private or public key) but in order to be unlocked - the OTHER key has to be used; using the same key to unlock wouldn&#8217;t work</strong>. And if you think that&#8217;s impossible - I have some good news for you - it most certainly is!</p><p>Let&#8217;s say you have two parties that want to communicate - Joe and Maria. Furthermore, they want to ensure that their communication is secure. How do they do that?</p><p>Simple! <strong>If Joe wants to talk to Maria, he&#8217;d just ask her for her public key</strong>. Given that the whole purpose of it is to be public, Maria can freely send it to anyone, including Joe. Now that Joe has Maria&#8217;s public key, he uses it to encrypt the message that he wants to send. And here&#8217;s the interesting thing &#8212; <strong>once you lock the message with Public key, the only way to unlock it is by using, you guessed it - the Private Key</strong>! So Joe is free to send the encrypted message over Internet because nobody except Maria will be able to decrypt it! It&#8217;s just beautiful! And if Maria were to contact the Joe, she&#8217;d take his Public key, encrypt the message and send it over insecure network.</p><p>Now the real beauty of this all happens once you reverse the process. Imagine you have a piece of information that can be unlocked with somebody&#8217;s Public key. What does that tell you? It tells you that whoever encrypted it - has the Private key :) Meaning that <strong>the only person who could have created and encrypted that is the owner of the Private Key</strong>. <strong>So this effectively means that by encrypting anything with your Private key is a very simple way of claiming ownership and identity</strong>.</p><p>For example, if I wanted to claim that email was sent by myself, and if I were to give you a way to confirm that, what I&#8217;d do is write an email, encrypt it with my private key and publish it on internet. Anyone can now take my public key, decrypt the email and confirm that, indeed, it was made by myself, because no one else has my Private key.</p><p>This exact process is how Digital Signatures work. What you do is you create something (e.g. a DLL file), and then you encrypt piece of it (usually the hash value of the file&#8217;s content) and store it alongside the DLL. You also want to pack your public key so that anyone can confirm the ownership, but it&#8217;d be totally valid as well to ask them to find your public key on a reputable source (e.g. your Website) and use that to confirm the ownership.</p><p>Consumers of your DLL can then calculate the hash value of that same file, and then use your public key to decrypt your signature and compare the two. If the current hash version matches the one that you digitally signed - file is genuine. If there&#8217;s a mismatch - file is not genuine.</p><p>And that&#8217;s really about it :) As I said - it&#8217;s really simple and I think it&#8217;s just beautiful; honestly. And hopefully it wraps up the story on why Strong-named assemblies contain the public key alongside them.</p><p>Anyway, in future articles I&#8217;ll slowly move my focus from assemblies towards Stacks and Heaps in .NET and CLR, with a special focus on Boxing &amp; Unboxing. And if you havent&#8217;t subscribed already, now might be a good time to do so :)</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.bitesizedengineering.com/subscribe?"><span>Subscribe now</span></a></p><p>Thanks for reading!</p><p></p><div><hr></div><p>Other articles from the CLR series:</p><ul><li><p><a href="https://www.bitesizedengineering.com/p/what-is-common-language-runtime-clr">What is Common Language Runtime (CLR) and why should I learn about it?</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/what-is-a-net-assembly">What is a .NET assembly?</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/what-is-assemblys-manifest">What is Assembly's Manifest?</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/weakly-and-strongly-named-assemblies">Weakly and Strongly-named Assemblies</a></p></li></ul>]]></content:encoded></item><item><title><![CDATA[Database Isolation Levels - explained as if you were building a Snowman]]></title><description><![CDATA[Chronicles of making Databases Fun]]></description><link>https://www.bitesizedengineering.com/p/database-isolation-levels-explained</link><guid isPermaLink="false">https://www.bitesizedengineering.com/p/database-isolation-levels-explained</guid><dc:creator><![CDATA[Mihailo Joksimovic]]></dc:creator><pubDate>Sat, 25 Mar 2023 06:01:18 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!KOab!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61460eec-370c-4b6c-b466-1198820bc471_2400x2400.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hi there! &#128075;</p><p>It&#8217;s Saturday and what a better way to spend 3 mins of your weekend than by refreshing your knowledge on DB&#8217;s Transaction Isolation Levels, right? RIGHT? &#129299;</p><p>I know, I know, who cares about that? It&#8217;s a boring and hard-to-grasp topic. And you have your fancy ORM that does it for you anyway &#8230; <strong>Which all makes sense until you learn that there are some weird scenarios like &#8220;Lost Updates&#8221; and &#8220;Dirty Reads&#8221;</strong>. Ouch!</p><p>&#8220;Well, no problem&#8221;, you say, &#8220;I&#8217;ll just tighten my Transaction Isolation Level. I don&#8217;t even need to understand how that works, because the higher the better&#8221;. And that&#8217;s true - higher isolation level is better; until you see the performance hit :)</p><p>Here&#8217;s what I want to do - <strong>I want to give you a frame in which to think about DB Transaction Isolation levels, but through lens of something that you can easily remember</strong>. Through the lens of Building a Snowman :)</p><p>As usual, we go with infographic first and then with more detailed text.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!KOab!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61460eec-370c-4b6c-b466-1198820bc471_2400x2400.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!KOab!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61460eec-370c-4b6c-b466-1198820bc471_2400x2400.png 424w, https://substackcdn.com/image/fetch/$s_!KOab!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61460eec-370c-4b6c-b466-1198820bc471_2400x2400.png 848w, https://substackcdn.com/image/fetch/$s_!KOab!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61460eec-370c-4b6c-b466-1198820bc471_2400x2400.png 1272w, https://substackcdn.com/image/fetch/$s_!KOab!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61460eec-370c-4b6c-b466-1198820bc471_2400x2400.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!KOab!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61460eec-370c-4b6c-b466-1198820bc471_2400x2400.png" width="1456" height="1456" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/61460eec-370c-4b6c-b466-1198820bc471_2400x2400.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1456,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:871860,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!KOab!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61460eec-370c-4b6c-b466-1198820bc471_2400x2400.png 424w, https://substackcdn.com/image/fetch/$s_!KOab!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61460eec-370c-4b6c-b466-1198820bc471_2400x2400.png 848w, https://substackcdn.com/image/fetch/$s_!KOab!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61460eec-370c-4b6c-b466-1198820bc471_2400x2400.png 1272w, https://substackcdn.com/image/fetch/$s_!KOab!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61460eec-370c-4b6c-b466-1198820bc471_2400x2400.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>I hope that was amusing enough :) Because, <strong>Isolation levels are actually really cool concepts to grasp</strong>. They do have their own set of intricacies, but, for starters, you should at least be aware on what they are.</p><p>Before I give you more context, I just want to let you know of the results of my 15-sec google search on Default Isolation levels in each DB:</p><ol><li><p>MySQL - REPEATABLE READ</p></li><li><p>PostgreSQL - READ COMMITTED</p></li><li><p>SQL Server - READ COMMITTED</p></li><li><p>Oracle - READ COMMITTED</p></li></ol><p>I want to emphasize that I literally did a 5-sec search for each and this is what came as a result. As usual, <strong>your mileage on your production database may vary, so do make sure to check it out</strong>.</p><p>So what is this all about? Well, it&#8217;s really simple - <strong>Transaction Isolation Levels are all about what happens when multiple users are trying to read &amp; write data from the same row</strong>. That&#8217;s concurrency. It tries to answer the question of &#8220;what will happen and how do I resolve the conflicts&#8221;. You can also think of it as two users trying to edit the same Excel row at the same time. That&#8217;d be concurrency as well.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.bitesizedengineering.com/subscribe?"><span>Subscribe now</span></a></p><p>And here&#8217;s what happens under each level:</p><ol><li><p>Under <strong>READ UNCOMMITTED</strong>, <strong>everything is fully transparent and everybody sees everything</strong>. If one user starts a transaction and starts editing the data, all other users will see all their changes even though they weren&#8217;t committed. This is great in cases where you know that concurrency is highly unlikely to happen (e.g. you have single writer and multiple readers or whatever). <br><br><strong>The problem would arise if user reads something that another user decides to roll back</strong>. We call this scenario a &#8220;dirty read&#8221; and depending on the context, consequences could range from &#8220;meh&#8221; to &#8220;well, we&#8217;re in deep shit now&#8221;.</p></li><li><p>Under <strong>READ COMMITTED</strong>, d<strong>atabase ensures that you see only the data that has been committed to DB</strong>. This is actually pretty good for most scenarios, except, and this is amusing - <strong>except if you wanted to ensure that you don&#8217;t see different data within a same transaction</strong>.<br><br>It&#8217;s a hard to grasp scenario so I&#8217;ll give you an example - long-running analytics query; or a machine learning thingy, whatever. Under READ COMMITTED, you would see some data that has been written to DB. All good. But imagine if your transaction was a long-running one (e.g. it lasts for several minutes). What could happen is that somebody modifies the data AGAIN, and if you re-read this you&#8217;d see a different value. <strong>This problem of possibly seeing DIFFERENT data under two SELECT statements in a single transaction is something that is not ideal for all scenarios</strong>. And that&#8217;s what gets solved with <strong>REPEATABLE READ</strong>.</p></li><li><p>Under <strong>REPEATABLE READ your transaction is guaranteed to see the EXACT SAME data all the time, for as long as transaction takes</strong>. Even if data changes in the meantime, you are still guaranteed that, in a single long-running transaction, you keep seeing the exact same values. <br><br>Frankly speaking, this is probably OK for 99% of the scenarios. Those 1% of cases would be if you want to ensure that no new data is added or removed while your transaction is running (e.g. think if your query depends on the exact number of rows). For such cases, you want to go with Seralizable Level.</p></li><li><p>Under <strong>SERIALIZABLE level, DB ensures that concurrent transactions are executed serially (i.e. one after another)</strong>. Think of it as physically locking the database while you are doing stuff in it. It&#8217;s super-slow because there&#8217;s no concurrency, but it&#8217;s effective if you need to ensure data is exactly the same.</p></li></ol><p>And that would be it, really :) As you can see - it&#8217;s not that hard, right? READ COMMITTED would serve most of the use-cases, but if you need to level-up the game - you can always upgrade to REPEATABLE read.</p><p>Finally, based on your use-case, <strong>you could also consider DOWNGRADING the isolation level</strong>. For example, if you are 100% sure that two transactions would never touch the same row, or that they&#8217;d operate on different columns - you can always consider easing the isolation and effectively improving the performance :)</p><p>Hope you enjoyed this article! If you did, I&#8217;d appreciate if you share it with others as well :)</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/p/database-isolation-levels-explained?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.bitesizedengineering.com/p/database-isolation-levels-explained?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p>You can also subscribe if you haven&#8217;t already :) I publish at least twice a week, but usually way more often:</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.bitesizedengineering.com/subscribe?"><span>Subscribe now</span></a></p><p>Thanks for reading!</p><p></p>]]></content:encoded></item><item><title><![CDATA[Weakly and Strongly-named Assemblies]]></title><description><![CDATA[Chronicles of .NET runtime - Part 4]]></description><link>https://www.bitesizedengineering.com/p/weakly-and-strongly-named-assemblies</link><guid isPermaLink="false">https://www.bitesizedengineering.com/p/weakly-and-strongly-named-assemblies</guid><dc:creator><![CDATA[Mihailo Joksimovic]]></dc:creator><pubDate>Thu, 23 Mar 2023 04:34:23 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!417N!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01c38109-05c9-4aaf-bd16-0d8ff8870ef1_1600x4000.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hey hey! &#128075;</p><p>You know what&#8217;s interesting? I initially created THREE infographics on this topic,  and that&#8217;s because I figured there&#8217;s a lot to unfuddle here. But as luck would have it, I didn&#8217;t have that much time to wrap them up, so I let them air-dry for couple of days. </p><p>Well, during this morning&#8217;s shower (yes, most of these are &#8216;created&#8217; during the shower-time), the thought hit me &#8212; why the heck would anyone want to read THREE graphics on Strongly-named assemblies? It can and should be compressed in a single one, and if anyone wants to explore more than that - they&#8217;ll be equipped with knowledge to do so.</p><p>So yeah, lo and behold, I bring you - ONE image :) And as usual - the graphic goes first and then more details will follow:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!417N!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01c38109-05c9-4aaf-bd16-0d8ff8870ef1_1600x4000.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!417N!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01c38109-05c9-4aaf-bd16-0d8ff8870ef1_1600x4000.png 424w, https://substackcdn.com/image/fetch/$s_!417N!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01c38109-05c9-4aaf-bd16-0d8ff8870ef1_1600x4000.png 848w, https://substackcdn.com/image/fetch/$s_!417N!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01c38109-05c9-4aaf-bd16-0d8ff8870ef1_1600x4000.png 1272w, https://substackcdn.com/image/fetch/$s_!417N!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01c38109-05c9-4aaf-bd16-0d8ff8870ef1_1600x4000.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!417N!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01c38109-05c9-4aaf-bd16-0d8ff8870ef1_1600x4000.png" width="1456" height="3640" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/01c38109-05c9-4aaf-bd16-0d8ff8870ef1_1600x4000.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:3640,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1090210,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!417N!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01c38109-05c9-4aaf-bd16-0d8ff8870ef1_1600x4000.png 424w, https://substackcdn.com/image/fetch/$s_!417N!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01c38109-05c9-4aaf-bd16-0d8ff8870ef1_1600x4000.png 848w, https://substackcdn.com/image/fetch/$s_!417N!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01c38109-05c9-4aaf-bd16-0d8ff8870ef1_1600x4000.png 1272w, https://substackcdn.com/image/fetch/$s_!417N!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01c38109-05c9-4aaf-bd16-0d8ff8870ef1_1600x4000.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Alright, cool! I hope that gave you an idea?</p><p>You know, in my opinion, <strong>Strongly-named is just a mouthful for a very simple concept - a file that is (digitally) signed</strong>. And yeah, Weakly-named is not an official name, but I &#8220;stole&#8221; it from <a href="https://www.amazon.com/CLR-via-4th-Developer-Reference/dp/0735667454">CLR via C#</a> (amazing book, btw!).</p><p>So wbat&#8217;s the whole deal? Well the deal is really simple - <strong>anyone could make a malicious assembly</strong>, fill it up with bunch of malware, name it System.dll and find a way to store it in a shared location on your system where .NET runtime would pick it up. Well, anyone could have been able to do this IF there was no way to verify whether the DLL is legit. And luckily - there is such way. And that way is something which has been fairly known for a while now - Digital Signing.</p><p>Let&#8217;s for a moment assume that you are Microsoft and you want to ship a new version of System.dll. I want to emphasize that, even though I currently am employed by Microsoft, my day to day job has NOTHING to do with .NET framework development. I work in Azure SQL MI. This scenario is 100% made up in my head in order to showcase a theoretical process:</p><ol><li><p>First things first &#8212;&gt; I&#8217;d update the code with whatever I wanted to do in System.dll and I&#8217;d build a new version of it. At this point I have a &#8220;weakly-named&#8221; assembly - it&#8217;s just a DLL without any info on the identity and ownership that could be validated.</p></li><li><p>Next, I&#8217;d take all the bytes that make up my DLL and run them through SHA256 hashing algorithm. You can think of it as <code>hash = SHA256(file_content)</code>.</p></li><li><p>Now that I have a fixed-size hash (hashes ALWAYS produce fixed-sized output, no matter how big the input is), next thing I do is take a Private Key that only couple of Key keepers in Microsoft have access to. It&#8217;s named &#8220;private&#8221; for a reason - access to it is severly restricted. What I do is I encrypt the file&#8217;s hash with this private key. Think of it as doing <code>ENCRYPT(file_content_hash, private_key)</code>. </p></li><li><p>The output of previous operation is what is called a DIGITAL SIGNATURE - it&#8217;s a hash of my file&#8217;s content, encrypted with the key that only I know about. Next, I add this digital signature to the assembly as well.</p></li><li><p>Finally, I add Microsoft&#8217;s PUBLIC KEY alongside this signature as well. Public Key is public for a reason - anybody can have it!</p></li><li><p>At this point, I embedded the digital signature and public key, and alongside other info in this file (name of assembly, version, culture, etc.) this makes the assembly STRONGLY-Named, meaning - anybody can verify that this was really created by Microsoft.</p></li></ol><p>But logical question to ask is - but HOW can anybody verify it? And the answer is simple - by using Public Key.</p><p>The thing is, if you don&#8217;t know how Private/Public key crypto works, this all sounds like bunch of complicated crap. Let me assure you that it&#8217;s REALLY SIMPLE and I&#8217;ll spend the whole next article explaining this topic.</p><p>For now, think of it this way - you have Private and Public key. Former you must keep super-secret, and latter you can print on your wall if you want. But here&#8217;s the trick - whatever you ENCODE with Private Key, can only be DECODED with Public Key! You CAN NOT decode with Private Key. It works in one-way only!</p><p>Same is true for Public Key - if you encode something with Public Key, the only way to decrypt it is by using the matching Private Key :) It&#8217;s beauty of the math at it&#8217;s finest.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.bitesizedengineering.com/subscribe?"><span>Subscribe now</span></a></p><p>So what this all means is that, if you want to verify genuiness of the System.dll, you&#8217;d take the file&#8217;s bytes, run them through SHA256 hashing algorithm and then take the digital signature (which, if you remember, is a Digital Signature that was encoded with Microsoft&#8217;s Private Key), decode it with the public key that is embedded in the assembly, and compare the two. If the hashes are IDENTICAL - then file is genuine and hasn&#8217;t been tampered with. If there is a mismatch - file has been tempered with!</p><p>In terms of pseudo-code, that would be:</p><pre><code># On Microsoft side

SIGNATURE = ENCRYPT(SHA256(FILE_CONTENT), PRIVATE_KEY)
EMBED(SIGNATURE in DLL)
EMBED(PUBLIC_KEY in DLL)

# On Client side

FILE_HASH = SHA256(FILE_CONTENT)
ORIGINAL_HASH = DECODE(SIGNATURE, PUBLIC_KEY)

IF FILE_HASH == ORIGINAL_HASH : file is Genuine</code></pre><p>But how do you know if public key is genuine, right? Well that&#8217;s where Certificate Authorities come into play. They are middle-man&#8217;s, trusted by everyone, whose only job is to stay safe and make guarantees about who owns which public key. But that&#8217;s a story for the next time. For now just take my word that there is a simple way to validate if Public Key belongs to Microsoft, and that is done by asking the &#8220;Trusted Authority&#8221;.</p><p>Long story made short - combo of these four (Assembly Name, Version, Culture, Public Key) is what uniquely identifies assembly and makes it a Strong-named one. Strong-named as in - it can be UNIQUELY identified. Remove the public key from equation and you have a weakly named assembly.</p><p>Last but not least - GAC. As you likely now, <strong>Global Assembly Cache (GAC) is a place where you store DLLs that you want to share</strong>. And that&#8217;s where all .NET&#8217;s DLLs reside. You can, of course, add your own assemblies there, but there&#8217;s a hard requirement that any assembly going into GAC must be strongly-named. This makes sense because GAC has the HIGHEST priority when CLR starts searching for assembly to load. If assembly is in GAC - everything else will be ignored and this is by design.</p><p>And that&#8217;s about it for today :) Next time I&#8217;m going to talk a bit about Cryptography and Private/Public keys and how they work. After that I&#8217;m likely moving either towards Assembly Metadata Tables (incredibly cool topic btw!) or towards the Stacks and Heaps in .NET. Until then, if you haven&#8217;t already, do consider subscribing as there&#8217;s lot more cool stuff to come!</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Bitesized Engineering! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>Thanks for reading!</p><div><hr></div><ul><li><p><a href="https://www.bitesizedengineering.com/p/what-is-common-language-runtime-clr">What is Common Language Runtime (CLR) and why should I learn about it?</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/what-is-a-net-assembly">What is a .NET assembly?</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/what-is-assemblys-manifest">What is Assembly's Manifest?</a></p></li></ul>]]></content:encoded></item><item><title><![CDATA[What is Assembly's Manifest?]]></title><description><![CDATA[Chronicles of .NET runtime - Part 3]]></description><link>https://www.bitesizedengineering.com/p/what-is-assemblys-manifest</link><guid isPermaLink="false">https://www.bitesizedengineering.com/p/what-is-assemblys-manifest</guid><dc:creator><![CDATA[Mihailo Joksimovic]]></dc:creator><pubDate>Mon, 20 Mar 2023 05:01:05 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!l8lQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81204307-0fd3-479f-8b7c-8ae1f8094500_1600x4000.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hi there! &#128075;</p><p>Last time I covered what assemblies are, and today I want to focus on one of the most important pieces that every assembly has - the Manifest file. And before you brush it off with &#8220;blah, who the heck cares about &#8216;Manifests&#8217;&#8221;, trust me - they can tell you A LOT. You may not need them right now, but not knowing what&#8217;s inside will severely limit what you are able to do with CLR. So, take my word and READ through this article.</p><p>As usual, we go with infographic first and then with the more detailed explanation:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!l8lQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81204307-0fd3-479f-8b7c-8ae1f8094500_1600x4000.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!l8lQ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81204307-0fd3-479f-8b7c-8ae1f8094500_1600x4000.png 424w, https://substackcdn.com/image/fetch/$s_!l8lQ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81204307-0fd3-479f-8b7c-8ae1f8094500_1600x4000.png 848w, https://substackcdn.com/image/fetch/$s_!l8lQ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81204307-0fd3-479f-8b7c-8ae1f8094500_1600x4000.png 1272w, https://substackcdn.com/image/fetch/$s_!l8lQ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81204307-0fd3-479f-8b7c-8ae1f8094500_1600x4000.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!l8lQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81204307-0fd3-479f-8b7c-8ae1f8094500_1600x4000.png" width="1456" height="3640" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/81204307-0fd3-479f-8b7c-8ae1f8094500_1600x4000.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:3640,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:862408,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!l8lQ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81204307-0fd3-479f-8b7c-8ae1f8094500_1600x4000.png 424w, https://substackcdn.com/image/fetch/$s_!l8lQ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81204307-0fd3-479f-8b7c-8ae1f8094500_1600x4000.png 848w, https://substackcdn.com/image/fetch/$s_!l8lQ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81204307-0fd3-479f-8b7c-8ae1f8094500_1600x4000.png 1272w, https://substackcdn.com/image/fetch/$s_!l8lQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81204307-0fd3-479f-8b7c-8ae1f8094500_1600x4000.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>I hope that was easy to digest? </p><p>First and foremost - Manifests are NOT unique to .NET. Not at all. You can find them in C++, Java, Rust, Ships and Airplanes carrying cargo, etc. They are EVERYWHERE.  Hell, there&#8217;s even an <a href="https://agilemanifesto.org/">Agile Manifesto</a>.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Jns0!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0dc5e10d-2ac6-4a31-b11e-9242e0b38a16_1344x702.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Jns0!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0dc5e10d-2ac6-4a31-b11e-9242e0b38a16_1344x702.png 424w, https://substackcdn.com/image/fetch/$s_!Jns0!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0dc5e10d-2ac6-4a31-b11e-9242e0b38a16_1344x702.png 848w, https://substackcdn.com/image/fetch/$s_!Jns0!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0dc5e10d-2ac6-4a31-b11e-9242e0b38a16_1344x702.png 1272w, https://substackcdn.com/image/fetch/$s_!Jns0!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0dc5e10d-2ac6-4a31-b11e-9242e0b38a16_1344x702.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Jns0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0dc5e10d-2ac6-4a31-b11e-9242e0b38a16_1344x702.png" width="1344" height="702" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0dc5e10d-2ac6-4a31-b11e-9242e0b38a16_1344x702.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:702,&quot;width&quot;:1344,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:124365,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Jns0!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0dc5e10d-2ac6-4a31-b11e-9242e0b38a16_1344x702.png 424w, https://substackcdn.com/image/fetch/$s_!Jns0!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0dc5e10d-2ac6-4a31-b11e-9242e0b38a16_1344x702.png 848w, https://substackcdn.com/image/fetch/$s_!Jns0!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0dc5e10d-2ac6-4a31-b11e-9242e0b38a16_1344x702.png 1272w, https://substackcdn.com/image/fetch/$s_!Jns0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0dc5e10d-2ac6-4a31-b11e-9242e0b38a16_1344x702.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Manifest is a summary of what&#8217;s &#8220;inside&#8221;. What is being &#8220;carried&#8221;. It can be a ship, a train, a JAR or a DLL, and Manifest&#8217;s job is to give a quick summary over it. In terms of CLR, think of it as &#8220;just reading the Manifest&#8221; instead of going through each line of code stored inside.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://www.bitesizedengineering.com/subscribe?"><span>Subscribe now</span></a></p><p>Speaking of .NET Assemblies in particular, Manifest is required to contain the following information:</p><ul><li><p><strong>Identity of the Assembly</strong> &#8212; what is the name of it, who created it, which version is it, etc. Additionally, if it&#8217;s a strong-named one (and we cover what this is in the next article!), there will be a way to confirm the identity of it.</p></li><li><p><strong>Content inside the Assembly </strong>&#8212; remember the <a href="https://www.bitesizedengineering.com/p/what-is-a-net-assembly">previous article</a> where I said that assembly can contain one or more files? Well, Manifest tells you WHAT are the files packed inside.</p></li><li><p><strong>External references </strong>&#8212; if you wrote a program that uses Console.Writeline, you&#8217;d be relying on existence of System.Console namespace, which is part of System.Console.dll assembly. This would be your external reference.</p></li></ul><p>Now instead of bullshitting too much and given the fact that you could find all this info online anyway, let me give you some actual meat. I&#8217;ll use our friend ILDASM.exe (Intermediate Language Dissasembler) to peak into Manifest of System.Console.dll:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!dxAZ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58da8cea-b26d-4260-b9af-82aa34661746_378x201.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!dxAZ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58da8cea-b26d-4260-b9af-82aa34661746_378x201.png 424w, https://substackcdn.com/image/fetch/$s_!dxAZ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58da8cea-b26d-4260-b9af-82aa34661746_378x201.png 848w, https://substackcdn.com/image/fetch/$s_!dxAZ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58da8cea-b26d-4260-b9af-82aa34661746_378x201.png 1272w, https://substackcdn.com/image/fetch/$s_!dxAZ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58da8cea-b26d-4260-b9af-82aa34661746_378x201.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!dxAZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58da8cea-b26d-4260-b9af-82aa34661746_378x201.png" width="378" height="201" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/58da8cea-b26d-4260-b9af-82aa34661746_378x201.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:201,&quot;width&quot;:378,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:5917,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!dxAZ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58da8cea-b26d-4260-b9af-82aa34661746_378x201.png 424w, https://substackcdn.com/image/fetch/$s_!dxAZ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58da8cea-b26d-4260-b9af-82aa34661746_378x201.png 848w, https://substackcdn.com/image/fetch/$s_!dxAZ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58da8cea-b26d-4260-b9af-82aa34661746_378x201.png 1272w, https://substackcdn.com/image/fetch/$s_!dxAZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58da8cea-b26d-4260-b9af-82aa34661746_378x201.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!I2JX!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0745eb64-0569-4bb1-b5dd-8249962716ad_1900x1018.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!I2JX!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0745eb64-0569-4bb1-b5dd-8249962716ad_1900x1018.png 424w, https://substackcdn.com/image/fetch/$s_!I2JX!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0745eb64-0569-4bb1-b5dd-8249962716ad_1900x1018.png 848w, https://substackcdn.com/image/fetch/$s_!I2JX!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0745eb64-0569-4bb1-b5dd-8249962716ad_1900x1018.png 1272w, https://substackcdn.com/image/fetch/$s_!I2JX!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0745eb64-0569-4bb1-b5dd-8249962716ad_1900x1018.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!I2JX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0745eb64-0569-4bb1-b5dd-8249962716ad_1900x1018.png" width="1456" height="780" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0745eb64-0569-4bb1-b5dd-8249962716ad_1900x1018.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:780,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:63817,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!I2JX!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0745eb64-0569-4bb1-b5dd-8249962716ad_1900x1018.png 424w, https://substackcdn.com/image/fetch/$s_!I2JX!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0745eb64-0569-4bb1-b5dd-8249962716ad_1900x1018.png 848w, https://substackcdn.com/image/fetch/$s_!I2JX!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0745eb64-0569-4bb1-b5dd-8249962716ad_1900x1018.png 1272w, https://substackcdn.com/image/fetch/$s_!I2JX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0745eb64-0569-4bb1-b5dd-8249962716ad_1900x1018.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Manifest of System.Console.dll</figcaption></figure></div><p>There&#8217;s a lot of content in there, and instead of pasting the images, I will paste parts of the text and then describe what each of them is:</p><pre><code>.module extern kernel32.dll
.module extern user32.dll</code></pre><p>These two are the native libraries (i.e. non-CLR DLL&#8217;s) that assembly requires. They are part of Windows API so feel free to google them if you want to get deeper understanding.</p><pre><code>.assembly extern System.Runtime
{
  .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A )                         // .?_....:
  .ver 7:0:0:0
}
.assembly extern System.Runtime.InteropServices
{
  .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A )                         // .?_....:
  .ver 7:0:0:0
}
.assembly extern System.Threading
{
  .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A )                         // .?_....:
  .ver 7:0:0:0
}
.assembly extern System.Memory
{
  .publickeytoken = (CC 7B 13 FF CD 2D DD 51 )                         // .{...-.Q
  .ver 7:0:0:0
}
.assembly extern System.Text.Encoding.Extensions
{
  .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A )                         // .?_....:
  .ver 7:0:0:0
}</code></pre><p>These are all the EXTERNAL REFERENCES &#8212; assemblies that this assembly requires to be loaded in order to function properly. What you see along with names are the public key tokens and versions for each. Version is probably obvious (i.e. it&#8217;s the version of assembly that is required), but if you are not familiar with Public Keys - don&#8217;t worry, it will be more clear in the next article. In short - it&#8217;s part of something called &#8220;Strong-named assemblies&#8221; and this Public Key token is a sort of fingerprint that identifies them.</p><pre><code>.assembly System.Console
{
  .custom instance void [System.Runtime]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) 
  .custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) 
  .custom instance void [System.Runtime]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78   // ....T..WrapNonEx
                                                                                                                   63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 )       // ceptionThrows.

  // --- The following custom attribute is added automatically, do not uncomment -------
  //  .custom instance void [System.Runtime]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [System.Runtime]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 02 00 00 00 00 00 ) 

  .custom instance void [System.Runtime]System.Runtime.CompilerServices.DisableRuntimeMarshallingAttribute::.ctor() = ( 01 00 00 00 ) 
  .custom instance void [System.Runtime]System.Runtime.Versioning.TargetFrameworkAttribute::.ctor(string) = ( 01 00 18 2E 4E 45 54 43 6F 72 65 41 70 70 2C 56   // ....NETCoreApp,V
                                                                                                              65 72 73 69 6F 6E 3D 76 37 2E 30 01 00 54 0E 14   // ersion=v7.0..T..
                                                                                                              46 72 61 6D 65 77 6F 72 6B 44 69 73 70 6C 61 79   // FrameworkDisplay
                                                                                                              4E 61 6D 65 08 2E 4E 45 54 20 37 2E 30 )          // Name..NET 7.0
  .custom instance void [System.Runtime]System.Reflection.AssemblyMetadataAttribute::.ctor(string,
                                                                                           string) = ( 01 00 15 2E 4E 45 54 46 72 61 6D 65 77 6F 72 6B   // ....NETFramework

 //
 // etc.
 //

  .publickey = (00 24 00 00 04 80 00 00 94 00 00 00 06 02 00 00   // .$..............
                00 24 00 00 52 53 41 31 00 04 00 00 01 00 01 00   // .$..RSA1........
                07 D1 FA 57 C4 AE D9 F0 A3 2E 84 AA 0F AE FD 0D   // ...W............
                E9 E8 FD 6A EC 8F 87 FB 03 76 6C 83 4C 99 92 1E   // ...j.....vl.L...
                B2 3B E7 9A D9 D5 DC C1 DD 9A D2 36 13 21 02 90   // .;.........6.!..
                0B 72 3C F9 80 95 7F C4 E1 77 10 8F C6 07 77 4F   // .r&lt;......w....wO
                29 E8 32 0E 92 EA 05 EC E4 E8 21 C0 A5 EF E8 F1   // ).2.......!.....
                64 5C 4C 0C 93 C1 AB 99 28 5D 62 2C AA 65 2C 1D   // d\L.....(]b,.e,.
                FA D6 3D 74 5D 6F 2D E5 F1 7E 5E AF 0F C4 96 3D   // ..=t]o-..~^....=
                26 1C 8A 12 43 65 18 20 6D C0 93 34 4D 5A D2 93 ) // &amp;...Ce. m..4MZ..
  .hash algorithm 0x00008004
  .ver 7:0:0:0
}</code></pre><p>These are the Attributes of our assembly (System.Console.dll) which represent various Metadata ranging from which Company published them (Microsoft) all the way to some Attributes that I have no faintest idea what they are. You can always google each one of them to see what&#8217;s their purpose. Some of these attributes are also visible when you click on Properties of the DLL:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!MSoU!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d2c9b70-0a08-4cbb-acd1-3de5283baef9_397x499.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!MSoU!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d2c9b70-0a08-4cbb-acd1-3de5283baef9_397x499.png 424w, https://substackcdn.com/image/fetch/$s_!MSoU!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d2c9b70-0a08-4cbb-acd1-3de5283baef9_397x499.png 848w, https://substackcdn.com/image/fetch/$s_!MSoU!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d2c9b70-0a08-4cbb-acd1-3de5283baef9_397x499.png 1272w, https://substackcdn.com/image/fetch/$s_!MSoU!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d2c9b70-0a08-4cbb-acd1-3de5283baef9_397x499.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!MSoU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d2c9b70-0a08-4cbb-acd1-3de5283baef9_397x499.png" width="397" height="499" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2d2c9b70-0a08-4cbb-acd1-3de5283baef9_397x499.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:499,&quot;width&quot;:397,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:20096,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!MSoU!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d2c9b70-0a08-4cbb-acd1-3de5283baef9_397x499.png 424w, https://substackcdn.com/image/fetch/$s_!MSoU!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d2c9b70-0a08-4cbb-acd1-3de5283baef9_397x499.png 848w, https://substackcdn.com/image/fetch/$s_!MSoU!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d2c9b70-0a08-4cbb-acd1-3de5283baef9_397x499.png 1272w, https://substackcdn.com/image/fetch/$s_!MSoU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d2c9b70-0a08-4cbb-acd1-3de5283baef9_397x499.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p> Also, &#8220;publickey&#8221; part is, like I said above, part of something called Strong-named assemblies, and Public Key is something you can use to confirm the identity. Again, no worries if you&#8217;re not familiar, it will become much more clear in the next article!</p><pre><code>.mresource public FxResources.System.Console.SR.resources
{
  // Offset: 0x00000000 Length: 0x00001ABF
}
.mresource public ILLink.Substitutions.xml
{
  // Offset: 0x00001AC3 Length: 0x000001F4
}</code></pre><p>These two appear to be two resources that have been embedded inside the Assembly as well, but I have no clue what they are used for. What you see for each are exact coordinates of where they start and where they end.</p><pre><code>.module System.Console.dll
// MVID: {BA4D167A-DE2E-4B21-827E-BAF8C9B71D53}
.custom instance void System.Runtime.CompilerServices.RefSafetyRulesAttribute::.ctor(int32) = ( 01 00 0B 00 00 00 00 00 ) 
.custom instance void System.Runtime.CompilerServices.NullablePublicOnlyAttribute::.ctor(bool) = ( 01 00 00 00 00 ) 
.custom instance void [System.Runtime]System.Runtime.CompilerServices.SkipLocalsInitAttribute::.ctor() = ( 01 00 00 00 ) 
.imagebase 0x00400000
.file alignment 0x00001000
.stackreserve 0x00100000
.subsystem 0x0003       // WINDOWS_CUI
.corflags 0x0000000c    //  IL_LIBRARY
// Image base: 0x0000020072620000</code></pre><p>.module defines which modules exist in this Manifest, .imagebase I presume is the offset where the CLR code starts, .file alignment I have no faintest idea what it does, .stackreserve is the size of the Stack that your assembly will get (this can be controlled with <a href="https://learn.microsoft.com/en-us/cpp/build/reference/stack-stack-allocations?view=msvc-170">/STACK linker option</a>) and for the rest I was just too lazy to look up what it is.</p><p>So what you&#8217;ve seen so far is a complete deep-dive into contents of an actual Manifest - Manifest of a System.Console.dll, which is an assembly that contains Console.Writeline command.</p><p>For reference sake, here&#8217;s an assembly of a C# app that contains a single Console.Writeline(&#8220;Hello world&#8221;):</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!zQ4F!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F693599f3-d899-4b36-a666-ba64c32a97b5_1641x734.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!zQ4F!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F693599f3-d899-4b36-a666-ba64c32a97b5_1641x734.png 424w, https://substackcdn.com/image/fetch/$s_!zQ4F!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F693599f3-d899-4b36-a666-ba64c32a97b5_1641x734.png 848w, https://substackcdn.com/image/fetch/$s_!zQ4F!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F693599f3-d899-4b36-a666-ba64c32a97b5_1641x734.png 1272w, https://substackcdn.com/image/fetch/$s_!zQ4F!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F693599f3-d899-4b36-a666-ba64c32a97b5_1641x734.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!zQ4F!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F693599f3-d899-4b36-a666-ba64c32a97b5_1641x734.png" width="1456" height="651" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/693599f3-d899-4b36-a666-ba64c32a97b5_1641x734.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:651,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:42426,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!zQ4F!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F693599f3-d899-4b36-a666-ba64c32a97b5_1641x734.png 424w, https://substackcdn.com/image/fetch/$s_!zQ4F!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F693599f3-d899-4b36-a666-ba64c32a97b5_1641x734.png 848w, https://substackcdn.com/image/fetch/$s_!zQ4F!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F693599f3-d899-4b36-a666-ba64c32a97b5_1641x734.png 1272w, https://substackcdn.com/image/fetch/$s_!zQ4F!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F693599f3-d899-4b36-a666-ba64c32a97b5_1641x734.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>All in all, I hope that Manifests are a bit more clear now. Their main purpose is to communicate who they are, what&#8217;s inside and what they need. There&#8217;s another interesting piece of info that is being stored in Assemblies, called Metadata Tables. They go into even more depth, and define pretty much every single parameter, class, method and variable that exists inside CLR. But that will be a topic for another time!</p><p>Next time I will be talking about Strong-named Assemblies. Until then, if you haven&#8217;t already, now&#8217;d be a good time to subscribe :)</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.bitesizedengineering.com/subscribe?"><span>Subscribe now</span></a></p><p>Thanks for reading!</p><div><hr></div><p>Other articles in this series:</p><ul><li><p><a href="https://www.bitesizedengineering.com/p/what-is-common-language-runtime-clr">What is Common Language Runtime (CLR) and why should I learn about it?</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/what-is-a-net-assembly">What is a .NET assembly?</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/weakly-and-strongly-named-assemblies">Weakly and Strongly-named Assemblies</a></p></li></ul>]]></content:encoded></item><item><title><![CDATA[8 Tips to Read More]]></title><description><![CDATA[Chronicles of very randomly interesting stuff]]></description><link>https://www.bitesizedengineering.com/p/8-tips-to-read-more</link><guid isPermaLink="false">https://www.bitesizedengineering.com/p/8-tips-to-read-more</guid><dc:creator><![CDATA[Mihailo Joksimovic]]></dc:creator><pubDate>Sat, 18 Mar 2023 05:30:12 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!eKqr!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2870f242-c824-42a5-9d8b-314d570916a1_3840x2160.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hi!</p><p>Before you mention it - you are right. This is a bit of a non-standard article. From time to time I like sharing some interesting facts that I spend a lot of time thinking about. And this is one of those :)</p><p>Let me share the infographic first and then I&#8217;ll add some more context:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!eKqr!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2870f242-c824-42a5-9d8b-314d570916a1_3840x2160.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!eKqr!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2870f242-c824-42a5-9d8b-314d570916a1_3840x2160.png 424w, https://substackcdn.com/image/fetch/$s_!eKqr!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2870f242-c824-42a5-9d8b-314d570916a1_3840x2160.png 848w, https://substackcdn.com/image/fetch/$s_!eKqr!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2870f242-c824-42a5-9d8b-314d570916a1_3840x2160.png 1272w, https://substackcdn.com/image/fetch/$s_!eKqr!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2870f242-c824-42a5-9d8b-314d570916a1_3840x2160.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!eKqr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2870f242-c824-42a5-9d8b-314d570916a1_3840x2160.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2870f242-c824-42a5-9d8b-314d570916a1_3840x2160.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1356008,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!eKqr!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2870f242-c824-42a5-9d8b-314d570916a1_3840x2160.png 424w, https://substackcdn.com/image/fetch/$s_!eKqr!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2870f242-c824-42a5-9d8b-314d570916a1_3840x2160.png 848w, https://substackcdn.com/image/fetch/$s_!eKqr!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2870f242-c824-42a5-9d8b-314d570916a1_3840x2160.png 1272w, https://substackcdn.com/image/fetch/$s_!eKqr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2870f242-c824-42a5-9d8b-314d570916a1_3840x2160.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>First and foremost - these are NOT some random tips that I picked up from internet. Nope. These are LITERALLY my first-hand experiences and I&#8217;ll elaborate on each one.</p><p>Before I do, I have to mention that almost a year ago, I wrote an article titled <a href="https://unstructed.tech/2021/04/09/how-i-learned-to-read-and-read-30-books-in-a-year/">How I learned to read (and read 30 books in a year)</a>. In a nutshell, I went from not reading a single book in my life to being an avid reader, and that article shares a lot of my personal details.</p><p>This one is more or less the summary of it :)</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.bitesizedengineering.com/subscribe?"><span>Subscribe now</span></a></p><p>So, let&#8217;s discuss each of the points:</p><ol><li><p><strong>Read more than one book at a time -</strong> this one was a literal game changer for me. Honestly. I remember being stuck for months reading Crime &amp; Punishment, not wanting to start anything new before I finished that one and yet even by thinking of it was making me want to rip my eyes off.<br><br>The thing is that you really need to read whatever you feel like reading at the moment. Just like your moods will vary, so should the book that you are reading.<br><br>My advice is to have at least two to three books, ideally of completely different genre, and just pick the one you feel like reading the most.</p></li><li><p><strong>Skim through books to get a sense of what&#8217;s inside</strong> <strong>-</strong> this is actually true for anything; especially when learning stuff. Khan Academy openly tells you to ALWAYS skim through lesson first, then do a quick read and then do a focused one. Same should be true for books.<br><br>Feel free to jump back &amp; forth. Check what&#8217;s coming. Go back to what you missed. <strong>You are not obliged to read in a linear fashion!</strong></p></li><li><p> <strong>Give it 15-20 minutes to get you engaged </strong>- and you might think that this is too short, but the thing is - we usually don&#8217;t start reading because we know we won&#8217;t have much time, while on the other hand we refuse to spend 15-20mins because it sounds too short, so what we end up is a freaking limbo sauce where we keep questioning but never deciding to take a course of action.<br><br>My advice - give book some short time to get you curious and if it fails to deliver it - forget it and move on.</p></li><li><p><strong>Drop the book you&#8217;re not enjoying </strong>- this is probably one of the best advices I ever read. You DO NOT have to finish every book; doubly so the ones you are bored with.<br><br>I mean, you are likely skimming through this article, right? Imagine if you had to read every single blog post from cover to cover? That&#8217;d leave you with zero time to actually explore and find stuff that you DO enjoy!</p></li><li><p><strong>Find genre that fits you </strong>- this is probably one of the most important advices. Explore and read variety of stuff until you find something that interests you. And once you do find it - feel free to exhaust the hell out of it!<br><br>One advice I heard some time ago was &#8220;find a writer that you like and read everything from them. And once you read everything, see what they liked and go and read that&#8221;. </p></li><li><p><strong>Take it slow </strong>- seriously. It&#8217;s ok to skip a day. Or a week. Reading should be fun and not a forced activity. Hell, there are days where I spend 3 minutes reading and that&#8217;s it. And yet there are days where I can&#8217;t stop thinking about that damn thing I read within 3 minutes so I spend hours exploring. Just go with the flow.</p></li><li><p><strong>Take notes while reading </strong>- and this is something that I struggled with. I clearly remember trying to read Game of Thrones and getting completely destroyed by sheer amount of characters and connections between them. But what I used to think is that having to write stuff down makes you dumb and that it&#8217;s not the &#8220;right way&#8221; to read.<br><br>Forget all the bullshit - take notes. Open excel. Draw charts if needed. There are tons of sites that actually give you great summaries of characters appearing in the book. Use them!</p></li><li><p><strong>It&#8217;s OK to re-read the same book</strong> - and not only is it OK but it&#8217;s actually a great thing. Books are PACKED with details and there&#8217;s simply NO WAY to gather all of them in one go.<br><br>There are some books I read three times so far and I&#8217;m absolutely planning to read them 10 more times for sure :)</p></li></ol><p>And that&#8217;d be about it! I&#8217;d be more than happy to hear your experiences!</p><p>P.S. Next article will be continuation of the Deep-dive into CLR series and will discuss Assembly&#8217;s Manifest file and what it is.</p><p>Until then!</p><p></p>]]></content:encoded></item><item><title><![CDATA[What is a .NET assembly?]]></title><description><![CDATA[Chronicles of .NET Runtime - Part 2]]></description><link>https://www.bitesizedengineering.com/p/what-is-a-net-assembly</link><guid isPermaLink="false">https://www.bitesizedengineering.com/p/what-is-a-net-assembly</guid><dc:creator><![CDATA[Mihailo Joksimovic]]></dc:creator><pubDate>Thu, 16 Mar 2023 04:53:13 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!5h6s!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8bff237-658b-4982-94ca-8fb7ab44a1a9_800x2000.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hi there! &#128075;</p><p>Today I&#8217;d like to talk about one of the basic ingredients of CLR (and .NET) - the Assemblies. As usual, the infographic goes first, followed by more detailed explanaten below.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!5h6s!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8bff237-658b-4982-94ca-8fb7ab44a1a9_800x2000.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!5h6s!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8bff237-658b-4982-94ca-8fb7ab44a1a9_800x2000.png 424w, https://substackcdn.com/image/fetch/$s_!5h6s!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8bff237-658b-4982-94ca-8fb7ab44a1a9_800x2000.png 848w, https://substackcdn.com/image/fetch/$s_!5h6s!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8bff237-658b-4982-94ca-8fb7ab44a1a9_800x2000.png 1272w, https://substackcdn.com/image/fetch/$s_!5h6s!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8bff237-658b-4982-94ca-8fb7ab44a1a9_800x2000.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!5h6s!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8bff237-658b-4982-94ca-8fb7ab44a1a9_800x2000.png" width="800" height="2000" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c8bff237-658b-4982-94ca-8fb7ab44a1a9_800x2000.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:2000,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:443565,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!5h6s!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8bff237-658b-4982-94ca-8fb7ab44a1a9_800x2000.png 424w, https://substackcdn.com/image/fetch/$s_!5h6s!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8bff237-658b-4982-94ca-8fb7ab44a1a9_800x2000.png 848w, https://substackcdn.com/image/fetch/$s_!5h6s!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8bff237-658b-4982-94ca-8fb7ab44a1a9_800x2000.png 1272w, https://substackcdn.com/image/fetch/$s_!5h6s!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8bff237-658b-4982-94ca-8fb7ab44a1a9_800x2000.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>I hope that was understandable :)</p><p>As you can see - at it&#8217;s most fundamental level, <strong>assemblies are a way of packaging and distributing code</strong>. I say &#8220;at most fundamental level&#8221; because there&#8217;s a lot more going on there, but we&#8217;ll cover that when the time comes. For now, you can think of them as archives that pack one or more files inside; it&#8217;s like a .tar, in a way.</p><p>One thing you can find inside the assembly, aside from the actual code itself, is <strong>Assembly Manifest</strong>. And if you stop and think about it, you soon realize that if you have one giant blob of ones and zeroes, and those ones and zeros belong to different files - how do you know what is what? And how do you even know if the assembly is safe to use? Or who created it? Or what the version is? Too many question that beg for an answer. And the answer is simple - Manifest.</p><p>I&#8217;ll expand lot more on <strong>Manifest and what&#8217;s inside </strong>as part of the next article, but <strong>for now just keep in mind that it&#8217;s like an Identity Card for your assembly</strong>. It provides info on WHO created it, WHICH version of the assembly is it, WHAT are the external dependencies that assembly has and what are the files that are INSIDE the assembly. That&#8217;s about it in a nutshell.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">If you&#8217;re enjoying the content so far, do consider subscribing! I publish two to three highly-summarized articles per week.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>Let me show you how to look into your assemblies. Because talking is cool, but seeing it in action makes all the difference in the world. First and foremost, locate your <a href="https://learn.microsoft.com/en-us/dotnet/framework/tools/ildasm-exe-il-disassembler">ILDASM.exe</a> (the MS IL Dissasembler). It comes with .NET installation so you should have it somewhere around.</p><p>Let&#8217;s look into the assembly that gets produced as a result of this simple code:</p><pre><code>using System;

namespace CsharpDllLibrary1
{
    public class Class1
    {
        private readonly Int32 x;

        public Class1(int x) 
        { 
            this.x = x;
        }

        public int GetOne()
        {
            return 1;
        }        
    }
}</code></pre><pre><code>ildasm.exe CsharpDllLibrary1.dll</code></pre><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!bl06!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe47e2a10-db5f-4148-b4f4-d26e1670bd87_474x252.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!bl06!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe47e2a10-db5f-4148-b4f4-d26e1670bd87_474x252.png 424w, https://substackcdn.com/image/fetch/$s_!bl06!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe47e2a10-db5f-4148-b4f4-d26e1670bd87_474x252.png 848w, https://substackcdn.com/image/fetch/$s_!bl06!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe47e2a10-db5f-4148-b4f4-d26e1670bd87_474x252.png 1272w, https://substackcdn.com/image/fetch/$s_!bl06!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe47e2a10-db5f-4148-b4f4-d26e1670bd87_474x252.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!bl06!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe47e2a10-db5f-4148-b4f4-d26e1670bd87_474x252.png" width="474" height="252" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e47e2a10-db5f-4148-b4f4-d26e1670bd87_474x252.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:252,&quot;width&quot;:474,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:23596,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!bl06!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe47e2a10-db5f-4148-b4f4-d26e1670bd87_474x252.png 424w, https://substackcdn.com/image/fetch/$s_!bl06!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe47e2a10-db5f-4148-b4f4-d26e1670bd87_474x252.png 848w, https://substackcdn.com/image/fetch/$s_!bl06!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe47e2a10-db5f-4148-b4f4-d26e1670bd87_474x252.png 1272w, https://substackcdn.com/image/fetch/$s_!bl06!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe47e2a10-db5f-4148-b4f4-d26e1670bd87_474x252.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>That&#8217;s cool, right? As you can see - there&#8217;s a Manifest, and then there&#8217;s my library namespace with a single class inside. Cool!</p><p>If you open the Manifest, you&#8217;ll see something like this:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Gpey!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc61edc6-53ff-489f-a8b2-c2a4b77535d7_1923x953.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Gpey!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc61edc6-53ff-489f-a8b2-c2a4b77535d7_1923x953.png 424w, https://substackcdn.com/image/fetch/$s_!Gpey!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc61edc6-53ff-489f-a8b2-c2a4b77535d7_1923x953.png 848w, https://substackcdn.com/image/fetch/$s_!Gpey!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc61edc6-53ff-489f-a8b2-c2a4b77535d7_1923x953.png 1272w, https://substackcdn.com/image/fetch/$s_!Gpey!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc61edc6-53ff-489f-a8b2-c2a4b77535d7_1923x953.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Gpey!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc61edc6-53ff-489f-a8b2-c2a4b77535d7_1923x953.png" width="1456" height="722" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bc61edc6-53ff-489f-a8b2-c2a4b77535d7_1923x953.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:722,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:169721,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Gpey!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc61edc6-53ff-489f-a8b2-c2a4b77535d7_1923x953.png 424w, https://substackcdn.com/image/fetch/$s_!Gpey!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc61edc6-53ff-489f-a8b2-c2a4b77535d7_1923x953.png 848w, https://substackcdn.com/image/fetch/$s_!Gpey!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc61edc6-53ff-489f-a8b2-c2a4b77535d7_1923x953.png 1272w, https://substackcdn.com/image/fetch/$s_!Gpey!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc61edc6-53ff-489f-a8b2-c2a4b77535d7_1923x953.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>That's a lot to digest if you&#8217;ve never encountered it. But what you see in the Manifest is basically the Table of Contents (i.e. what&#8217;s inside) plus the Identity Information (which is missing btw but more about it later on).</p><p>And if we sneak peak into GetOne() method, you will see something like this:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!zJg8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70d5e88e-f2c0-40ae-aa3f-63aa1589f16b_775x333.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!zJg8!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70d5e88e-f2c0-40ae-aa3f-63aa1589f16b_775x333.png 424w, https://substackcdn.com/image/fetch/$s_!zJg8!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70d5e88e-f2c0-40ae-aa3f-63aa1589f16b_775x333.png 848w, https://substackcdn.com/image/fetch/$s_!zJg8!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70d5e88e-f2c0-40ae-aa3f-63aa1589f16b_775x333.png 1272w, https://substackcdn.com/image/fetch/$s_!zJg8!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70d5e88e-f2c0-40ae-aa3f-63aa1589f16b_775x333.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!zJg8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70d5e88e-f2c0-40ae-aa3f-63aa1589f16b_775x333.png" width="775" height="333" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/70d5e88e-f2c0-40ae-aa3f-63aa1589f16b_775x333.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:333,&quot;width&quot;:775,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:26005,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!zJg8!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70d5e88e-f2c0-40ae-aa3f-63aa1589f16b_775x333.png 424w, https://substackcdn.com/image/fetch/$s_!zJg8!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70d5e88e-f2c0-40ae-aa3f-63aa1589f16b_775x333.png 848w, https://substackcdn.com/image/fetch/$s_!zJg8!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70d5e88e-f2c0-40ae-aa3f-63aa1589f16b_775x333.png 1272w, https://substackcdn.com/image/fetch/$s_!zJg8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70d5e88e-f2c0-40ae-aa3f-63aa1589f16b_775x333.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>So in a nutshell, what&#8217;s inside the assembly is Manifest, CLR code and optional resources (which I&#8217;ll leave for some other time). I&#8217;d actually encourage you to locate ILDASM.exe on your computer, find a DLL (or EXE) that was built using some .NET language, and explore what&#8217;s inside. You will learn the most by actually doing it.</p><p>Another thing that&#8217;s interesting to mention is - <strong>how does Windows know whether the EXE or DLL contains native code?</strong> And the answer lies in - <strong>based on the header information</strong>. To be valid, EXEs and DLLs have to conform to the <a href="https://learn.microsoft.com/en-us/windows/win32/debug/pe-format">Portable Executable (PE)</a> format (and I&#8217;ll write more about it as well!) and <strong>what CLR does is that it stores info inside that header that the code that follows should be run through the CLR</strong>. But again, don&#8217;t sweat over it, I&#8217;ll cover this in a separate article.</p><p>Finally, in the graphic above, I made honorable mention of <strong>Global Assembly Cache (GAC)</strong>. That&#8217;s a very fancy name for a folder that holds commonly shared DLLs (e.g. .NET framework&#8217;s DLLs). GAC is one of the folders where CLR runtime looks for assemblies if they can&#8217;t be located in your program&#8217;s local folder. But there&#8217;s a trick to it - <strong>for assembly to be elligible to be inside GAC folder, it has to be Strong-named</strong>. Strong-named is yet another fancy word for a very simple thing - <strong>digitally signed file, whose identity you can verify</strong>. </p><p>If you&#8217;re not familiar with digital signing of content, well, it&#8217;s really a cool way of claiming ownership of stuff using Private/Public keys. Owner of assembly &#8220;signs&#8221; the file (think of it as placing a seal on it) with their Private key, and they provide a (public) key which can only break the seal signed with owner&#8217;s private key. It can be a bit mind-boggling but <strong>for now just think of it as a very simple &amp; efficient way to confirm ownership of the assembly</strong>.</p><p>And that would be all I had to share for today! If you enjoyed this content, do consider subscribing. In the next few articles I will talk more about Manifest and Strong-named assemblies before moving on to discuss the Memory Management features of CLR.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.bitesizedengineering.com/subscribe?"><span>Subscribe now</span></a></p><p>Thanks for reading!</p><div><hr></div><p>Other articles in this series:</p><ul><li><p><a href="https://www.bitesizedengineering.com/p/what-is-common-language-runtime-clr">What is Common Language Runtime (CLR) and why should I learn about it?</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/what-is-assemblys-manifest">What is Assembly's Manifest?</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/weakly-and-strongly-named-assemblies">Weakly and Strongly-named Assemblies</a></p></li></ul>]]></content:encoded></item><item><title><![CDATA[C++ and Memory Allocation - for People in a Hurry]]></title><description><![CDATA[17 high-quality infographics on how C++ and Memory Allocations work together]]></description><link>https://www.bitesizedengineering.com/p/c-and-memory-allocation-for-people</link><guid isPermaLink="false">https://www.bitesizedengineering.com/p/c-and-memory-allocation-for-people</guid><dc:creator><![CDATA[Mihailo Joksimovic]]></dc:creator><pubDate>Mon, 13 Mar 2023 05:07:01 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!mPHn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F67c91e34-55b8-4368-8339-c1a13fde866b_700x1750.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hi there! &#128075;</p><p>If you&#8217;re an old subscriber, you likely know that I&#8217;ve published 17 infographics on C++ and Memory Management. This actually took me some 40+ (or maybe even 50+) hours to complete but I really had tremendous fun while doing it :)</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Bitesized Engineering! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>If you are a newcomer, well, I created bunch of infographics and they look similar to this one:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!mPHn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F67c91e34-55b8-4368-8339-c1a13fde866b_700x1750.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!mPHn!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F67c91e34-55b8-4368-8339-c1a13fde866b_700x1750.png 424w, https://substackcdn.com/image/fetch/$s_!mPHn!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F67c91e34-55b8-4368-8339-c1a13fde866b_700x1750.png 848w, https://substackcdn.com/image/fetch/$s_!mPHn!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F67c91e34-55b8-4368-8339-c1a13fde866b_700x1750.png 1272w, https://substackcdn.com/image/fetch/$s_!mPHn!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F67c91e34-55b8-4368-8339-c1a13fde866b_700x1750.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!mPHn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F67c91e34-55b8-4368-8339-c1a13fde866b_700x1750.png" width="700" height="1750" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/67c91e34-55b8-4368-8339-c1a13fde866b_700x1750.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1750,&quot;width&quot;:700,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:462901,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!mPHn!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F67c91e34-55b8-4368-8339-c1a13fde866b_700x1750.png 424w, https://substackcdn.com/image/fetch/$s_!mPHn!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F67c91e34-55b8-4368-8339-c1a13fde866b_700x1750.png 848w, https://substackcdn.com/image/fetch/$s_!mPHn!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F67c91e34-55b8-4368-8339-c1a13fde866b_700x1750.png 1272w, https://substackcdn.com/image/fetch/$s_!mPHn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F67c91e34-55b8-4368-8339-c1a13fde866b_700x1750.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>What I want to do now is create one mega-article that will link all the articles (and infographics) that I&#8217;ve published in this series. Each one contains a high-quality image and an extended description. You can also find a print-quality PDF <a href="https://drive.google.com/file/d/1iGkwcNIP_WDXd03ryDIaUp8F1MHuqezQ/view?usp=sharing">here</a>.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">I publish at least twice a week. Stay up to date by subscribing for free.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>As far as I'm concerned, you are free to use them in any way you want - download, print, copy, distribute, &#8230; do whatever you like as long as you keep my credentials on the bottom :)</p><p>Table of contents:</p><p><em>(Note: I suggest bookmarking this page)</em></p><ul><li><p><a href="https://www.bitesizedengineering.com/p/c-and-data-types">C++ and Data Types</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/where-are-my-programs-bits">Where are my program&#8217;s bits?</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/stacks-heaps-and-other-funny-places">Stacks, Heaps and other funny places</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/so-what-is-a-stack-really">What is a Stack, really?</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/why-is-stack-faster-than-heap">Why is Stack (much) faster than the heap?</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/stack-attack">Stack attack</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/what-happens-when-you-type-the-new">The magic of keyword &#8220;new&#8221;</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/heaps-and-stacks-explained-like-youre-five">Heaps and Stacks - explained like you're five</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/why-does-memory-leak">Why does Memory Leak?</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/pointers-and-references-our-school">Pointers &amp; References - our school day boogeymans</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/how-windows-allocates-memory">How Windows allocates memory</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/memory-allocation-through-heap-api">Memory allocation through Heap API</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/virtual-adressing-and-why-every-process">Virtual Adressing and Why every process sees the same memory space</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/virtual-memory-api-and-all-the-cool">Virtual Memory API and all the cool stuff you can do with it</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/memory-allocation-functions-a-primer">Memory Allocation Functions - a primer</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/raii-and-smart-pointers-smarter-way">RAII and Smart Pointers - smarter way to work with your memory</a></p></li></ul><p>P.S. Check out other series that I&#8217;ve covered:</p><ul><li><p><a href="https://www.bitesizedengineering.com/p/containers-for-people-in-hurry">(Windows) Containers, for People in a Hurry</a></p></li><li><p>SQL Server&#8217;s Storage Engine Internals</p></li><li><p>Deep-dive into DB Indexes</p></li><li><p>Deep-dive into CLR (in progress)</p></li></ul><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Bitesized Engineering! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[What is Common Language Runtime (CLR) and why should I learn about it?]]></title><description><![CDATA[Chronicles of .NET Runtime - Part 1]]></description><link>https://www.bitesizedengineering.com/p/what-is-common-language-runtime-clr</link><guid isPermaLink="false">https://www.bitesizedengineering.com/p/what-is-common-language-runtime-clr</guid><dc:creator><![CDATA[Mihailo Joksimovic]]></dc:creator><pubDate>Sat, 11 Mar 2023 07:39:48 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!Ofwx!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a944532-964d-48c8-a8e8-49350a95e4b6_1600x4000.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hi! &#128075;</p><p>I&#8217;ve been talking about it for a while now. Given that the last article on <a href="https://www.bitesizedengineering.com/p/raii-and-smart-pointers-smarter-way">C++ and memory allocation</a>  went out yesterday, it&#8217;s time to start a new chapter and new deep-dive series.</p><p>Before I do, I&#8217;d like to take a moment and reflect on one thing. And this is something that has been hanging over my head for a while now. If you are just casually scrolling through Bitesized articles, you&#8217;d probably think something along the lines of &#8220;wow, this guy makes context switches like it&#8217;s nothing!&#8221;. In a way, you&#8217;d be right - I started writing about SQL Server&#8217;s Storage Engine Internals, then switched to Containers, then spent some months on DB Indexes, before finally moving to C++ and Memory Allocation. Wanna know how that works and feels?</p><p>It sucks. And it scares the shit out of me. Honestly. It is exciting, for sure, because I get to explore cool new things that I&#8217;m really interested in, but trust me - it&#8217;s scary! Starting ANYTHING new is always scary.</p><p>But here&#8217;s the gist - <strong>I learned that after two or three articles it becomes a breeze and then it just starts flowing</strong>. Really. So I just need to survive to break the ice of the new topic and then I&#8217;m sure it will get easier :)</p><p>Anyway, I just wanted to share those thoughts with you. Back to the original topic - CLR. As usual, the infographic first and then we go with some more detailed explanation!</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Ofwx!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a944532-964d-48c8-a8e8-49350a95e4b6_1600x4000.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Ofwx!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a944532-964d-48c8-a8e8-49350a95e4b6_1600x4000.png 424w, https://substackcdn.com/image/fetch/$s_!Ofwx!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a944532-964d-48c8-a8e8-49350a95e4b6_1600x4000.png 848w, https://substackcdn.com/image/fetch/$s_!Ofwx!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a944532-964d-48c8-a8e8-49350a95e4b6_1600x4000.png 1272w, https://substackcdn.com/image/fetch/$s_!Ofwx!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a944532-964d-48c8-a8e8-49350a95e4b6_1600x4000.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Ofwx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a944532-964d-48c8-a8e8-49350a95e4b6_1600x4000.png" width="1456" height="3640" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4a944532-964d-48c8-a8e8-49350a95e4b6_1600x4000.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:3640,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1106789,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Ofwx!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a944532-964d-48c8-a8e8-49350a95e4b6_1600x4000.png 424w, https://substackcdn.com/image/fetch/$s_!Ofwx!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a944532-964d-48c8-a8e8-49350a95e4b6_1600x4000.png 848w, https://substackcdn.com/image/fetch/$s_!Ofwx!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a944532-964d-48c8-a8e8-49350a95e4b6_1600x4000.png 1272w, https://substackcdn.com/image/fetch/$s_!Ofwx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a944532-964d-48c8-a8e8-49350a95e4b6_1600x4000.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>I hope you found that useful :)</p><p>Let&#8217;s start from the beginning - do you need to know about CLR in order to use C# (or any other .NET based language)? No.</p><p>So why SHOULD YOU spend time on it? In my opinion - for the same reason you decide to learn anything - <strong>once you understand the internals, you get a whole new perspective on how to write more performant and reliable code</strong>.</p><p>Back to the topic, though. So, what&#8217;s the Common Language Runtime (CLR )? Well, it&#8217;s the Runtime Engine for .NET. Just like JVM is for Java. It makes your .NET code actually DO stuff. But there&#8217;s a lot more to it.</p><p>All your .NET code compiles into something that is, these days, referred to as Microsoft&#8217;s Intermediate Language (MSIL). Here&#8217;s a very simple app:</p><pre><code>namespace SampleCSharpApp2
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, World!");
        }
    }
}</code></pre><p>And here&#8217;s the MSIL code that was generated for it (hint: .NET bundles an app called <a href="https://learn.microsoft.com/en-us/dotnet/framework/tools/ildasm-exe-il-disassembler">ILDASM.exe</a> - an IL Dissasembler; search for it in your .NET directory):</p><pre><code>.class private auto ansi beforefieldinit Program
       extends [System.Runtime]System.Object
{
  .custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
  .method private hidebysig static void  '&lt;Main&gt;$'(string[] args) cil managed
  {
    .entrypoint
    // Code size       12 (0xc)
    .maxstack  8
    IL_0000:  ldstr      "Hello, World!"
    IL_0005:  call       void [System.Console]System.Console::WriteLine(string)
    IL_000a:  nop
    IL_000b:  ret
  } // end of method Program::'&lt;Main&gt;$'

  .method public hidebysig specialname rtspecialname
          instance void  .ctor() cil managed
  {
    // Code size       8 (0x8)
    .maxstack  8
    IL_0000:  ldarg.0
    IL_0001:  call       instance void [System.Runtime]System.Object::.ctor()
    IL_0006:  nop
    IL_0007:  ret
  } // end of method Program::.ctor

} // end of class Program</code></pre><p>If you&#8217;ve never encountered it before - that&#8217;s OK. It might take a moment or two to get adjusted to it. What you are looking at is disassembled MSIL code :) It looks like assembly, but it&#8217;s way more readable and understandable. Well, for contrast, here&#8217;s an actual assembly code for the same thing:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!k5yM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85d6e0b3-dc49-483e-8a25-3ca68dafe7b2_816x687.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!k5yM!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85d6e0b3-dc49-483e-8a25-3ca68dafe7b2_816x687.png 424w, https://substackcdn.com/image/fetch/$s_!k5yM!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85d6e0b3-dc49-483e-8a25-3ca68dafe7b2_816x687.png 848w, https://substackcdn.com/image/fetch/$s_!k5yM!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85d6e0b3-dc49-483e-8a25-3ca68dafe7b2_816x687.png 1272w, https://substackcdn.com/image/fetch/$s_!k5yM!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85d6e0b3-dc49-483e-8a25-3ca68dafe7b2_816x687.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!k5yM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85d6e0b3-dc49-483e-8a25-3ca68dafe7b2_816x687.png" width="816" height="687" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/85d6e0b3-dc49-483e-8a25-3ca68dafe7b2_816x687.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:687,&quot;width&quot;:816,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:60401,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!k5yM!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85d6e0b3-dc49-483e-8a25-3ca68dafe7b2_816x687.png 424w, https://substackcdn.com/image/fetch/$s_!k5yM!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85d6e0b3-dc49-483e-8a25-3ca68dafe7b2_816x687.png 848w, https://substackcdn.com/image/fetch/$s_!k5yM!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85d6e0b3-dc49-483e-8a25-3ca68dafe7b2_816x687.png 1272w, https://substackcdn.com/image/fetch/$s_!k5yM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85d6e0b3-dc49-483e-8a25-3ca68dafe7b2_816x687.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>You have to agree that MSIL is a &#8220;bit&#8221; more understandable, right?</p><p>Anyway, we&#8217;ll talk lot more about MSIL in the upcoming articles. And if you haven&#8217;t subscribed already, now&#8217;s a good time to do so:</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.bitesizedengineering.com/subscribe?"><span>Subscribe now</span></a></p><p><strong>The whole point of MSIL and CLR is that you can run it on any architecture and any platform</strong>. And that&#8217;s made possible by the fact that MSIL is being interpreted by CLR, which takes those instructions, compiles them to native-code for the target platform (e.g. if you are executing the code above on Linux, it&#8217;d be compiled to Linux&#8217;s native code) and executes them. <strong>This process of compiling just before executing is called JIT Compilation (Just In Time Compilation)</strong>. It has some pros &amp; cons but we&#8217;ll also spend some time discussing that in future articles. What&#8217;s important to remember for now is that CLR compiles the code to machine-readable language, whereas Java interprets the code and emulates it through Java&#8217;s VM. Again, don&#8217;t worry too much about it for now - it&#8217;ll become more clear as we progress.</p><p>What&#8217;s uniquely cool about MSIL is that, strictly speaking, you are NOT limited to C#, F#, VB, etc. As long as you write a program that takes ANY source code (e.g. Python, PHP, C++, etc.) and converts it to MSIL - you can have it run on CLR. And people actually did just that:</p><ul><li><p><a href="https://ironpython.net/">IronPython</a> compiles Python to CLR</p></li><li><p><a href="https://github.com/peachpiecompiler/peachpie">PeachPie</a> compiles PHP to CLR</p></li><li><p><a href="https://learn.microsoft.com/en-us/cpp/dotnet/walkthrough-compiling-a-cpp-program-that-targets-the-clr-in-visual-studio?view=msvc-170">Managed C++</a> compiles C++ into MSIL</p></li><li><p><a href="https://learn.microsoft.com/en-us/powershell/scripting/overview?view=powershell-7.3">Windows&#8217; PowerShell</a> was built on top of CLR</p></li><li><p>etc.</p></li></ul><p>I hope you got the idea so far :) MSIL is awesome and we&#8217;ll definitely talk much more about it in upcoming articles.</p><p>And this is where I&#8217;ll stop for today. I hope that this article gave you an idea of what&#8217;s coming. And trust me - a LOT MORE interesting stuff is about to come throughout the following weeks! Next time I will be talking about Assemblies, the fundamental unit of deployment for CLR.</p><p>Until then!</p><p>P.S. If you enjoyed this article, do consider sharing it:</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/p/what-is-common-language-runtime-clr?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.bitesizedengineering.com/p/what-is-common-language-runtime-clr?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p>Thanks for reading!</p><div><hr></div><p>Other articles in this series:</p><ul><li><p><a href="https://www.bitesizedengineering.com/p/what-is-a-net-assembly">What is a .NET assembly?</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/what-is-assemblys-manifest">What is Assembly's Manifest?</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/weakly-and-strongly-named-assemblies">Weakly and Strongly-named Assemblies</a></p></li></ul><p></p>]]></content:encoded></item><item><title><![CDATA[RAII and Smart Pointers - smarter way to work with your memory]]></title><description><![CDATA[Chronicles of Memory Management - Part 15]]></description><link>https://www.bitesizedengineering.com/p/raii-and-smart-pointers-smarter-way</link><guid isPermaLink="false">https://www.bitesizedengineering.com/p/raii-and-smart-pointers-smarter-way</guid><dc:creator><![CDATA[Mihailo Joksimovic]]></dc:creator><pubDate>Tue, 07 Mar 2023 04:30:22 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!SHYQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44026a09-31e0-426d-b4a9-f7cfa5f5ab32_1600x4000.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hi! &#128075;</p><p>We&#8217;re nearing the end of these C++ Memory Allocation series and there are two more things that I want to talk about &#8212; <em>RAII and Smart pointers</em>, which is the topic of today, and <em>Alternative Memory Allocation libraries</em> which will be the topic of the next article.</p><p>As usual, first we go with the bitesized infographic and then the more detailed info will follow. Enjoy!</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!SHYQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44026a09-31e0-426d-b4a9-f7cfa5f5ab32_1600x4000.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!SHYQ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44026a09-31e0-426d-b4a9-f7cfa5f5ab32_1600x4000.png 424w, https://substackcdn.com/image/fetch/$s_!SHYQ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44026a09-31e0-426d-b4a9-f7cfa5f5ab32_1600x4000.png 848w, https://substackcdn.com/image/fetch/$s_!SHYQ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44026a09-31e0-426d-b4a9-f7cfa5f5ab32_1600x4000.png 1272w, https://substackcdn.com/image/fetch/$s_!SHYQ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44026a09-31e0-426d-b4a9-f7cfa5f5ab32_1600x4000.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!SHYQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44026a09-31e0-426d-b4a9-f7cfa5f5ab32_1600x4000.png" width="1456" height="3640" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/44026a09-31e0-426d-b4a9-f7cfa5f5ab32_1600x4000.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:3640,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1376977,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!SHYQ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44026a09-31e0-426d-b4a9-f7cfa5f5ab32_1600x4000.png 424w, https://substackcdn.com/image/fetch/$s_!SHYQ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44026a09-31e0-426d-b4a9-f7cfa5f5ab32_1600x4000.png 848w, https://substackcdn.com/image/fetch/$s_!SHYQ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44026a09-31e0-426d-b4a9-f7cfa5f5ab32_1600x4000.png 1272w, https://substackcdn.com/image/fetch/$s_!SHYQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44026a09-31e0-426d-b4a9-f7cfa5f5ab32_1600x4000.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Cool! I hope you found that useful?</p><p>I&#8217;d like to share some additional thoughts on RAII (Resource Allocation Is Initialization) first. I was actually reading the <a href="https://www.amazon.com/Tour-2nd-Depth-Bjarne-Stroustrup/dp/0134997832">&#8220;Tour of C++"</a> by the C++&#8217;s father himself - Bjarne Stroustrup and I clearly remember him saying <em>&#8220;so people kept forgetting to deallocate memory, opening up various memory leaks, so I came up with this acronym - RAII, which was supposed to put an end to it&#8221;</em>. </p><p>Honestly speaking, I tried really hard to understand the logic behind the name and, sadly, I just kept failing; miserably so. It just doesn&#8217;t make ANY sense to me. I was happy to learn that others find it &#8220;weird&#8221;, so to speak, as well, and people apparently came up with a better acronym - Stack Bound Resource Management (SBRM). Now this one is troubling to me as well, but at least it communicates the idea a bit better. So let&#8217;s focus on that.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.bitesizedengineering.com/subscribe?"><span>Subscribe now</span></a></p><p>What both RAII and SBRM advocate is that any memory allocation (e.g. constructing any object or allocating raw bits of memory) should be wrapped inside a SINGLE object. And this object should have Destructor defined which should cleanup any initializations that were made. Here&#8217;s a simple example:</p><pre><code>class DataPackage
{
private:
&#9;int* data;

public:
&#9;DataPackage()
&#9;{
&#9;&#9;data = new int(12345);
&#9;}

&#9;~DataPackage()
&#9;{
&#9;&#9;delete data;
&#9;}
};

void useData()
{
&#9;DataPackage* data = new DataPackage();

&#9;// Do something useful with data ..

&#9;// And feel free to forget to remove it ...
&#9;// Once the function ends and "data" goes 
&#9;// out of scope, destructor will be called 
&#9;// and dynamic memory will be cleaned up.
}</code></pre><p>What we do above is we do dynamic allocation of an INT, but we do it inside an object. And we can really forget about it because once the pointer to DataPackage goes out of scope, the destructor will be called and the memory will be cleaned up.</p><p>Compare that to this:</p><pre><code>void leakyData()
{
&#9;int* data = new int(12345);

&#9;// Do something useful with data ..

&#9;// Unless you delete it explicitly, you leak 32 bits
&#9;// every time you call leakyData() ;/
}
</code></pre><p>That makes sense? I hope it does. And I guess that &#8220;Stack Bound Resource Management&#8221; makes more sense as well now. All your locally allocated variables are put on Stack (hence the name) and once they go out of scope, Destructor is automatically called (assuming there IS one, obviously). So it really boils down to (ab)using this nifty feature of Stack vars being cleaned up automatically. It&#8217;s like a free garbage collector!</p><p>I was also happy to learn that <a href="https://doc.rust-lang.org/rust-by-example/scope/raii.html#:~:text=Rust%20enforces%20RAII%20(Resource%20Acquisition,its%20owned%20resources%20are%20freed.">Rust actually enforces RAII to be used</a>, which is one of the principles that language is built on :)</p><p>Speaking of stuff that relies on RAII, not mentioning Smart Pointers would be a disservice to reader :) I was actually thinking of naming the article &#8220;There&#8217;s nothing inherently Smart about Smart Pointers&#8221;, but eventually decided against it. Smart Pointers are smart because they rely on simple things &#8212; Stacks that call Destructors once the object goes out of scope :)</p><p>If you want to learn details, I thinks <a href="https://www.drdobbs.com/cpp/the-new-csmarter-pointers/184403837">this article</a> that mentions them back in 2002 can give you a solid context, whereas <a href="https://stackoverflow.com/questions/106508/what-is-a-smart-pointer-and-when-should-i-use-one">this StackOverflow answer</a> goes in a really nice and yet approachable depth.</p><p>Given that I understand you are likely in a hurry, I&#8217;ll try to be short and sweet. Smart Pointers rely on Destructors and that&#8217;s fine. What&#8217;s different about them is how are they supposed to be used. <a href="https://learn.microsoft.com/en-us/cpp/cpp/how-to-create-and-use-unique-ptr-instances?view=msvc-170">Unique Pointer</a> is just like your regular pointer - it encapsulates a single resource. Shared Pointer is more of a thing that you might want to copy to multiple places, while letting the <a href="https://learn.microsoft.com/en-us/cpp/cpp/how-to-create-and-use-shared-ptr-instances?view=msvc-170">Shared Pointer</a> keep the count. Once the count drops to zero - destructor removes the original resource. And finally, <a href="https://learn.microsoft.com/en-us/cpp/cpp/how-to-create-and-use-weak-ptr-instances?view=msvc-170">Weak Pointer</a> is similar to Shared Pointer, except that it doesn&#8217;t count :) And that&#8217;s actually all there is to it.</p><p>Here are some really simple examples to give you a clue:</p><pre><code>auto data = std::make_unique&lt;int&gt;(12345);

auto shared_data = std::make_shared&lt;int&gt;(12345);

// This won't work - unique_ptr can NOT be copied and C++ reports an error.
passDataByValue(data);

// This will work, and shared_data's ref. count will increase by 1 here
passDataByValue(shared_data);</code></pre><p>Here&#8217;s a live example:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!YJ-o!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9143227d-93cb-420b-8985-dc0c6040d7c6_928x473.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!YJ-o!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9143227d-93cb-420b-8985-dc0c6040d7c6_928x473.png 424w, https://substackcdn.com/image/fetch/$s_!YJ-o!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9143227d-93cb-420b-8985-dc0c6040d7c6_928x473.png 848w, https://substackcdn.com/image/fetch/$s_!YJ-o!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9143227d-93cb-420b-8985-dc0c6040d7c6_928x473.png 1272w, https://substackcdn.com/image/fetch/$s_!YJ-o!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9143227d-93cb-420b-8985-dc0c6040d7c6_928x473.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!YJ-o!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9143227d-93cb-420b-8985-dc0c6040d7c6_928x473.png" width="928" height="473" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9143227d-93cb-420b-8985-dc0c6040d7c6_928x473.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:473,&quot;width&quot;:928,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:47465,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!YJ-o!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9143227d-93cb-420b-8985-dc0c6040d7c6_928x473.png 424w, https://substackcdn.com/image/fetch/$s_!YJ-o!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9143227d-93cb-420b-8985-dc0c6040d7c6_928x473.png 848w, https://substackcdn.com/image/fetch/$s_!YJ-o!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9143227d-93cb-420b-8985-dc0c6040d7c6_928x473.png 1272w, https://substackcdn.com/image/fetch/$s_!YJ-o!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9143227d-93cb-420b-8985-dc0c6040d7c6_928x473.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Notice the &#8220;_Uses&#8221; being set to 1 here. Now see what happens once we pass it by value:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Jq6u!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febea92ab-3c57-472c-a40b-69a4712b3891_927x468.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Jq6u!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febea92ab-3c57-472c-a40b-69a4712b3891_927x468.png 424w, https://substackcdn.com/image/fetch/$s_!Jq6u!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febea92ab-3c57-472c-a40b-69a4712b3891_927x468.png 848w, https://substackcdn.com/image/fetch/$s_!Jq6u!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febea92ab-3c57-472c-a40b-69a4712b3891_927x468.png 1272w, https://substackcdn.com/image/fetch/$s_!Jq6u!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febea92ab-3c57-472c-a40b-69a4712b3891_927x468.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Jq6u!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febea92ab-3c57-472c-a40b-69a4712b3891_927x468.png" width="927" height="468" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ebea92ab-3c57-472c-a40b-69a4712b3891_927x468.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:468,&quot;width&quot;:927,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:44961,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Jq6u!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febea92ab-3c57-472c-a40b-69a4712b3891_927x468.png 424w, https://substackcdn.com/image/fetch/$s_!Jq6u!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febea92ab-3c57-472c-a40b-69a4712b3891_927x468.png 848w, https://substackcdn.com/image/fetch/$s_!Jq6u!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febea92ab-3c57-472c-a40b-69a4712b3891_927x468.png 1272w, https://substackcdn.com/image/fetch/$s_!Jq6u!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febea92ab-3c57-472c-a40b-69a4712b3891_927x468.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>As you can see, _Uses is now 2. What this means is that once we go out of scope of passDataByValue(), destructor of Shared Pointer will be called, but given that _Uses is &gt; 1 - the original object won&#8217;t be removed. It is only after the SECOND function is done that the object will be cleaned up.</p><p>And that&#8217;s about it for today! :) If you found it useful, I&#8217;d appreciate if you share it with your network:</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/p/raii-and-smart-pointers-smarter-way?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.bitesizedengineering.com/p/raii-and-smart-pointers-smarter-way?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p>Next time I&#8217;m going to talk about alternative libraries for Memory Allocation. Until then!</p><div><hr></div><p>Other articles from the C++ Memory Management series:</p><ul><li><p><a href="https://www.bitesizedengineering.com/p/pointers-and-references-our-school">Pointers &amp; References - our school day boogeymans</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/heaps-and-stacks-explained-like-youre-five">Heaps and Stacks - explained like you're five</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/why-does-memory-leak">Why does Memory Leak?</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/pointers-and-references-our-school">Pointers &amp; References - our school day boogeymans</a></p></li></ul><p></p>]]></content:encoded></item><item><title><![CDATA[Memory Allocation Functions - a primer]]></title><description><![CDATA[Chronicles of Memory Management - Part 14]]></description><link>https://www.bitesizedengineering.com/p/memory-allocation-functions-a-primer</link><guid isPermaLink="false">https://www.bitesizedengineering.com/p/memory-allocation-functions-a-primer</guid><dc:creator><![CDATA[Mihailo Joksimovic]]></dc:creator><pubDate>Sun, 05 Mar 2023 08:38:28 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!uTJw!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7a9bc40f-4629-4049-8ac4-be2b2c3bdfeb_800x2000.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hi there! &#128075;</p><p>Somebody once said that the perfect way to spend Sunday is by doing a recap of what you learned in BitesizedEngineering series on C++ Memory Allocation :)</p><p>As usual, the bitesized graphic first and then more details for those eager to understand more details:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!uTJw!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7a9bc40f-4629-4049-8ac4-be2b2c3bdfeb_800x2000.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!uTJw!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7a9bc40f-4629-4049-8ac4-be2b2c3bdfeb_800x2000.png 424w, https://substackcdn.com/image/fetch/$s_!uTJw!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7a9bc40f-4629-4049-8ac4-be2b2c3bdfeb_800x2000.png 848w, https://substackcdn.com/image/fetch/$s_!uTJw!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7a9bc40f-4629-4049-8ac4-be2b2c3bdfeb_800x2000.png 1272w, https://substackcdn.com/image/fetch/$s_!uTJw!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7a9bc40f-4629-4049-8ac4-be2b2c3bdfeb_800x2000.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!uTJw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7a9bc40f-4629-4049-8ac4-be2b2c3bdfeb_800x2000.png" width="800" height="2000" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7a9bc40f-4629-4049-8ac4-be2b2c3bdfeb_800x2000.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:2000,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:376729,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!uTJw!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7a9bc40f-4629-4049-8ac4-be2b2c3bdfeb_800x2000.png 424w, https://substackcdn.com/image/fetch/$s_!uTJw!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7a9bc40f-4629-4049-8ac4-be2b2c3bdfeb_800x2000.png 848w, https://substackcdn.com/image/fetch/$s_!uTJw!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7a9bc40f-4629-4049-8ac4-be2b2c3bdfeb_800x2000.png 1272w, https://substackcdn.com/image/fetch/$s_!uTJw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7a9bc40f-4629-4049-8ac4-be2b2c3bdfeb_800x2000.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>I hope that was useful :)</p><p>So, in a nutshell, what we have is:</p><ul><li><p><strong>malloc() </strong>&#8212; which I&#8217;d guess stands for &#8220;<strong>M</strong>emory <strong>Alloc</strong>ation&#8221; is a C function for allocating the memory. Given that C++ was meant as an extension of C (hence the &#8220;++&#8221; meaning an increment of C), malloc() exists in C++ but people generally recommend avoiding it. Here&#8217;s a nice <a href="https://stackoverflow.com/questions/184537/in-what-cases-do-i-use-malloc-and-or-new">StackOverflow</a> thread if you want details.</p></li><li><p><strong>&#8220;new&#8221; expression &#8212; </strong>which I occasionally call &#8220;keyword new&#8221; for reasons known to myself only, is basically a C++ way for allocating memory. I&#8217;ll discuss more details about it below.</p></li><li><p><strong>HeapAlloc() </strong>&#8212; is part of Windows&#8217; API and as such should be used ONLY if you&#8217;re targeting Windows only. For any other case you should really stick to &#8220;new&#8221;.</p></li><li><p><strong>VirtualAlloc() &#8212;</strong> is also part of Windows&#8217; API and represents the lowest-level API that you can interact with. It enables some amazing stuff, but also comes with a cost. We&#8217;ll discuss it below as well.</p></li></ul><pre><code>void* memory = malloc(1024);

char* memory = new char[1024];

void* memory = HeapAlloc(GetCurrentProcess(), 
    HEAP_GENERATE_EXCEPTIONS | HEAP_ZERO_MEMORY, 1024);

// You get back 4096 bytes (i.e. 1 page)
void* memory = VirtualAlloc(nullptr, 1024, MEM_COMMIT, PAGE_READWRITE);</code></pre><p>As you can see above, &#8220;new&#8221; is the only one that works with actual Data Types. All others work with raw bytes. What&#8217;s more, <a href="https://www.bitesizedengineering.com/p/memory-allocation-through-heap-api">HeapAlloc()</a> and <a href="https://www.bitesizedengineering.com/p/virtual-memory-api-and-all-the-cool">VirtualAlloc()</a> require some additional properties, which, frankly, are the exact reason why you&#8217;d likely be using them in the first place - to tweak the memory allocation behavior :)</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.bitesizedengineering.com/subscribe?"><span>Subscribe now</span></a></p><p>Now let&#8217;s answer the <strong>&#8220;so, what should I use?&#8221;</strong> question. And the common answer seems to be - <strong>unless you know WHAT and WHY you are doing it, you should likely stick to expression &#8220;new&#8221;</strong>.</p><p>One of the main benefits of the &#8220;new&#8221; vs everything else is that it guarantees type-safety. As in - with &#8220;new&#8221; you ensure that you get only as much bytes as you need for DATA TYPE that you want to create (remember when we discussed that <a href="https://www.bitesizedengineering.com/p/c-and-data-types">C++ is all about Data Types</a>?). On the other hand, with malloc(), HeapAlloc() and VirtualAlloc() <strong>you get back a </strong><code>void*</code><strong> &#8212; which is a confusing way to inform you that you get a pointer, pointing to some memory address, but it&#8217;s up to you to figure out how big that SOMETHING is (hence the &#8220;void&#8221; part)</strong>.</p><p>Another &#8220;issue&#8221; <strong>with malloc(), HeapAlloc() and VirtualAlloc() is that you get back a NULL if there&#8217;s no free memory to allocate</strong>. &#8220;new&#8221; will generate exception, which is a preferred OOP way to handle exceptional scenarios. You can override this behavior with Heap and VirtualAlloc(), but still, it&#8217;s something to keep in mind.</p><p><strong>Yet another thing to keep in mind is that &#8220;new&#8221; will invoke a Constructor (and Destructor)</strong>, whereas other APIs won&#8217;t do that. I guess this communicates that &#8220;new&#8221; is much more than a Memory Allocator, right? It&#8217;s really ALL what C++ is about - <a href="https://www.bitesizedengineering.com/p/c-and-data-types">Data Types</a>. And this aligns really nicely for those coming from pretty much any managed language, where you think of &#8220;new&#8221; as a way to construct an object :)</p><p>Finally, one cool question that one might ask is &#8212; so, if &#8220;new&#8221; is all about Data Types, and specifying data types, how do you allocate large chunks of memory then? And the answer is quite simple - you can use the <a href="https://www.bitesizedengineering.com/p/what-happens-when-you-type-the-new">operator new</a> and allocate bigger chunks internally (by invoking malloc() / HeapAlloc() / VirtualAlloc() under the hood).</p><p><em>Fun fact btw: in Windows, &#8220;new&#8221; actually uses malloc() under the hood, and malloc() calls HeapAlloc() which in turn calls VirtualAlloc(). You can read more about it <a href="https://www.bitesizedengineering.com/p/how-windows-allocates-memory">here</a>.</em></p><p>And that&#8217;d be about it for today :) Next week, as I <a href="https://www.bitesizedengineering.com/p/announcing-new-series-on-clr">announced before</a>, I&#8217;m going to start sharing some insights on how CLR works (i.e. a .NET&#8217;s Runtime Engine), but in parallel I&#8217;ll be working on some articles on how memory paging works, and what are User and Kernel modes in Windows (and how do they affect the memory). Until then, if you liked this, I&#8217;d appreciate if you share it! :)</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/p/memory-allocation-functions-a-primer?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.bitesizedengineering.com/p/memory-allocation-functions-a-primer?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p>Thanks for reading!</p><div><hr></div><p>Other articles from the C++ Memory Management series:</p><ul><li><p><a href="https://www.bitesizedengineering.com/p/pointers-and-references-our-school">Pointers &amp; References - our school day boogeymans</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/how-windows-allocates-memory">How Windows allocates memory</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/memory-allocation-through-heap-api">Memory allocation through Heap API</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/virtual-memory-api-and-all-the-cool">Virtual Memory API and all the cool stuff you can do with it</a></p></li></ul><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Bitesized Engineering! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Virtual Memory API and all the cool stuff you can do with it]]></title><description><![CDATA[Chronicles of Memory Management - Part 13]]></description><link>https://www.bitesizedengineering.com/p/virtual-memory-api-and-all-the-cool</link><guid isPermaLink="false">https://www.bitesizedengineering.com/p/virtual-memory-api-and-all-the-cool</guid><dc:creator><![CDATA[Mihailo Joksimovic]]></dc:creator><pubDate>Wed, 01 Mar 2023 03:30:39 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!9yWe!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fceb5d07f-ae72-464e-8353-71a6824d326c_1600x4000.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Last time I talked about <a href="https://www.bitesizedengineering.com/p/virtual-adressing-and-why-every-process">Virtual Addressing</a> and all the interesting stuff that come with it. I guess it shan&#8217;t come as a surprise that there&#8217;s an actual API that allows you to work with it directy - Virtual Memory API.</p><p>As usual, the infographic goes first and then some additional thoughts. Enjoy!</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!9yWe!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fceb5d07f-ae72-464e-8353-71a6824d326c_1600x4000.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!9yWe!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fceb5d07f-ae72-464e-8353-71a6824d326c_1600x4000.png 424w, https://substackcdn.com/image/fetch/$s_!9yWe!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fceb5d07f-ae72-464e-8353-71a6824d326c_1600x4000.png 848w, https://substackcdn.com/image/fetch/$s_!9yWe!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fceb5d07f-ae72-464e-8353-71a6824d326c_1600x4000.png 1272w, https://substackcdn.com/image/fetch/$s_!9yWe!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fceb5d07f-ae72-464e-8353-71a6824d326c_1600x4000.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!9yWe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fceb5d07f-ae72-464e-8353-71a6824d326c_1600x4000.png" width="1456" height="3640" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ceb5d07f-ae72-464e-8353-71a6824d326c_1600x4000.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:3640,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1051352,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!9yWe!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fceb5d07f-ae72-464e-8353-71a6824d326c_1600x4000.png 424w, https://substackcdn.com/image/fetch/$s_!9yWe!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fceb5d07f-ae72-464e-8353-71a6824d326c_1600x4000.png 848w, https://substackcdn.com/image/fetch/$s_!9yWe!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fceb5d07f-ae72-464e-8353-71a6824d326c_1600x4000.png 1272w, https://substackcdn.com/image/fetch/$s_!9yWe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fceb5d07f-ae72-464e-8353-71a6824d326c_1600x4000.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>I hope you found that useful! If not - reach out my complaints mailbox, eh :)</p><p>So here&#8217;s the deal - Virtual Memory API represents the lowest-level API your process can interact with in order to allocate memory. But here&#8217;s a kicker - at that level, you can&#8217;t really ask for BYTES. I mean, technically you CAN, but what you will get back are PAGES. E.g. if you ask for 10 bytes - you will get 4096 bytes back (i.e. a single page). If you ask for 10.000 bytes you will get 3 pages back, etc.</p><p>Here&#8217;s an example:</p><pre><code>PMEMORY_BASIC_INFORMATION mbi = new MEMORY_BASIC_INFORMATION();

// Ask for 10 bytes
LPVOID memory = VirtualAlloc(nullptr, 10, MEM_COMMIT, PAGE_READWRITE);

VirtualQuery(memory, mbi, sizeof(*mbi));

// mbi.RegionSize will report 4096 bytes</code></pre><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!oh73!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ea17579-fc59-4888-9587-9a18ae96d4a1_929x462.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!oh73!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ea17579-fc59-4888-9587-9a18ae96d4a1_929x462.png 424w, https://substackcdn.com/image/fetch/$s_!oh73!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ea17579-fc59-4888-9587-9a18ae96d4a1_929x462.png 848w, https://substackcdn.com/image/fetch/$s_!oh73!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ea17579-fc59-4888-9587-9a18ae96d4a1_929x462.png 1272w, https://substackcdn.com/image/fetch/$s_!oh73!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ea17579-fc59-4888-9587-9a18ae96d4a1_929x462.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!oh73!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ea17579-fc59-4888-9587-9a18ae96d4a1_929x462.png" width="929" height="462" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5ea17579-fc59-4888-9587-9a18ae96d4a1_929x462.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:462,&quot;width&quot;:929,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:45397,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!oh73!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ea17579-fc59-4888-9587-9a18ae96d4a1_929x462.png 424w, https://substackcdn.com/image/fetch/$s_!oh73!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ea17579-fc59-4888-9587-9a18ae96d4a1_929x462.png 848w, https://substackcdn.com/image/fetch/$s_!oh73!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ea17579-fc59-4888-9587-9a18ae96d4a1_929x462.png 1272w, https://substackcdn.com/image/fetch/$s_!oh73!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ea17579-fc59-4888-9587-9a18ae96d4a1_929x462.png 1456w" sizes="100vw"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>As you can imagine, given that HeapAlloc() and others call VirtualAlloc(), that means that they have to do some book-keeping in order to deal with pages properly. But that&#8217;s a different story for another time.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.bitesizedengineering.com/subscribe?"><span>Subscribe now</span></a></p><p>Anyway here are some cool things that VirtualAlloc() allows you to do:</p><ol><li><p><strong>Reserve memory</strong> -- which is a really nifty process completely made possible by the fact that OS uses Virtual Addressing instead of physical one. By "reserving" range of memory, you are effectively telling your system that the range of pages you are asking for SHOULD NOT be given to anyone else (i.e. any "new" and "HeapAllocs()" won't get those addresses). This operation does NOTHING to Physical RAM, and it's 100% logical (i.e. all of this happens on the OS' memory manager level) and as such is pretty cheap to do.<br><br>Here&#8217;s an example:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!yOAh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb090d1e-a639-4c62-a3c0-aefedded4882_1376x291.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!yOAh!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb090d1e-a639-4c62-a3c0-aefedded4882_1376x291.png 424w, https://substackcdn.com/image/fetch/$s_!yOAh!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb090d1e-a639-4c62-a3c0-aefedded4882_1376x291.png 848w, https://substackcdn.com/image/fetch/$s_!yOAh!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb090d1e-a639-4c62-a3c0-aefedded4882_1376x291.png 1272w, https://substackcdn.com/image/fetch/$s_!yOAh!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb090d1e-a639-4c62-a3c0-aefedded4882_1376x291.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!yOAh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb090d1e-a639-4c62-a3c0-aefedded4882_1376x291.png" width="1376" height="291" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/db090d1e-a639-4c62-a3c0-aefedded4882_1376x291.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:291,&quot;width&quot;:1376,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:49365,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!yOAh!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb090d1e-a639-4c62-a3c0-aefedded4882_1376x291.png 424w, https://substackcdn.com/image/fetch/$s_!yOAh!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb090d1e-a639-4c62-a3c0-aefedded4882_1376x291.png 848w, https://substackcdn.com/image/fetch/$s_!yOAh!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb090d1e-a639-4c62-a3c0-aefedded4882_1376x291.png 1272w, https://substackcdn.com/image/fetch/$s_!yOAh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb090d1e-a639-4c62-a3c0-aefedded4882_1376x291.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>As you can see - I asked for total of 1GB and 10 Megs, but what&#8217;s really committed is just 10 Megs.</p></li><li><p><strong>Protect Memory</strong> -- which if you are thinking in OOP terms would be similar to defining a constant or a private property. You can really set some cool properties  on memory pages (e.g. make memory read-only, or completely disable any access) and, for example, ensure that no malicious code can actually do anything nasty. Check out <a href="https://learn.microsoft.com/en-us/windows/win32/Memory/memory-protection-constants">official docs</a> for list of all Memory Protection constatns.</p></li><li><p><strong>Lock Memory</strong> -- which pretty much means to tell OS not to move your bits from RAM to Hard Disk. And this is really cool because getting your bits back from Hard Drive actually bears some cost and hurts efficiency, so asking for your bits to always stay in physical RAM ensures maximum performance. On the other hand this makes your program pretty greedy so you really have to strike a balance here.</p></li></ol><p>You can check the <a href="https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/">official docs</a> for list of all interesting things you could do.</p><p>And that&#8217;d be about it for today :) Next time we're going to talk about comparison of various allocation functions. </p><p>I also want to emphasize that, as <a href="https://www.bitesizedengineering.com/p/announcing-new-series-on-clr">announced before</a>, I started creating graphics on the CLR topic so that's coming out next week as well!</p><p>Until then, if you enjoyed this article or learned anything new - I&#8217;d appreciate if you share it with your network!</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/p/virtual-memory-api-and-all-the-cool?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.bitesizedengineering.com/p/virtual-memory-api-and-all-the-cool?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p>Thanks for reading!</p><div><hr></div><p>Other articles from the C++ Memory Management series:</p><ul><li><p><a href="https://www.bitesizedengineering.com/p/virtual-adressing-and-why-every-process">Virtual Adressing and Why every process sees the same memory space</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/memory-allocation-through-heap-api">Memory allocation through Heap API</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/how-windows-allocates-memory">How Windows allocates memory</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/pointers-and-references-our-school">Pointers &amp; References - our school day boogeymans</a></p></li></ul><p></p>]]></content:encoded></item><item><title><![CDATA[Virtual Adressing and Why every process sees the same memory space]]></title><description><![CDATA[Chronicles of Memory Management - Part 12]]></description><link>https://www.bitesizedengineering.com/p/virtual-adressing-and-why-every-process</link><guid isPermaLink="false">https://www.bitesizedengineering.com/p/virtual-adressing-and-why-every-process</guid><dc:creator><![CDATA[Mihailo Joksimovic]]></dc:creator><pubDate>Sun, 26 Feb 2023 12:39:38 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!d0xe!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdbe3c7dc-31f8-4c3f-b073-99dead382b69_1600x4000.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>This is one of those articles that I didn&#8217;t plan on writing. Seriously. My plan was to cover <a href="https://www.bitesizedengineering.com/p/heaps-and-stacks-explained-like-youre-five">Heaps</a>, <a href="https://www.bitesizedengineering.com/p/memory-allocation-through-heap-api">Heap API</a> and then write about Virtual functions and Virtual Memory allocation. But then I realized I never explained what Virtual Memory and Virtual Addressing is. Bummer!</p><p>As we do usually, first the bitesized infographic and then the more detailed explanation below!</p><p>Enjoy!</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!d0xe!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdbe3c7dc-31f8-4c3f-b073-99dead382b69_1600x4000.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!d0xe!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdbe3c7dc-31f8-4c3f-b073-99dead382b69_1600x4000.png 424w, https://substackcdn.com/image/fetch/$s_!d0xe!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdbe3c7dc-31f8-4c3f-b073-99dead382b69_1600x4000.png 848w, https://substackcdn.com/image/fetch/$s_!d0xe!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdbe3c7dc-31f8-4c3f-b073-99dead382b69_1600x4000.png 1272w, https://substackcdn.com/image/fetch/$s_!d0xe!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdbe3c7dc-31f8-4c3f-b073-99dead382b69_1600x4000.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!d0xe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdbe3c7dc-31f8-4c3f-b073-99dead382b69_1600x4000.png" width="1456" height="3640" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/dbe3c7dc-31f8-4c3f-b073-99dead382b69_1600x4000.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:3640,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1090525,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!d0xe!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdbe3c7dc-31f8-4c3f-b073-99dead382b69_1600x4000.png 424w, https://substackcdn.com/image/fetch/$s_!d0xe!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdbe3c7dc-31f8-4c3f-b073-99dead382b69_1600x4000.png 848w, https://substackcdn.com/image/fetch/$s_!d0xe!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdbe3c7dc-31f8-4c3f-b073-99dead382b69_1600x4000.png 1272w, https://substackcdn.com/image/fetch/$s_!d0xe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdbe3c7dc-31f8-4c3f-b073-99dead382b69_1600x4000.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>A&#8217;ight, I hope you found that useful. If not - well, at least I know I gave my best.</p><p>The truth is that I lied to you before. <strong>I lied when I said that memory addresses that you get back from OS are <a href="https://www.bitesizedengineering.com/p/stacks-heaps-and-other-funny-places">RAM addresses</a></strong>. They are not. And some of you probably figured that I&#8217;m a liar and you stopped reading. That&#8217;s OK. Thing is - I think this was a WHITE LIE. A lie that told with a greater purpose. <strong>Purpose of making it simpler to digest the content at the moment</strong>. But now I&#8217;m giving you the full picture (and I swear that was the only lie I told!).</p><p>Thing is - <strong>you never ever get to see the actual physical RAM addresses</strong>. Never. Ever. Hell, I actually went way and beyond to figure out if there&#8217;s even a way to do so! No matter how privileged your process is, <strong>you ALWAYS see Virtual Address space</strong>. The actual conversion from Virtual to Physical happens in the OS&#8217;  Kernel itself!</p><p>But why is that? Well I guess I explained it in the infographic below, but I&#8217;ll repeat for those with fuse-short attention span:</p><ol><li><p><strong>Process can ask for more memory than there is Physical RAM </strong>&#8212; this isn&#8217;t such a big of a problem in these days of massive servers with hundreds of gigabytes of RAM. At least not a big enough of a problem to bother you. But to get an actual picture, I want to take you back to 32-bit Windows era. The era when Windows supported maximum of 4 gigs of RAM (simply due to number of bits available for addressing!).<br><br>During the 4 gigs and 32bits era, Windows would usually split your RAM into two halves - User Space and System Space. And it&#8217;d split it in 50:50 ratio. So your program, along with all other programs out there gets 2 gigs of RAM and Windows uses other 2 gigs for, you know, Kernel, Drivers and all other things going under the hood.<br><br>Question then becomes &#8212; how the heck do you start a Chrome browser with 2 gigs of RAM, right? Not to mention Chrome and, god forbid, a Calculator. The answer is simple - you don&#8217;t. Or at least - you couldn&#8217;t. And that sucked because some people really wanted to use Chrome.<br><br>So how do you solve this unsolvable problem? Well, you lie. Just like I lied a bit when I told you that addresses reference physical RAM addresses, <strong>so does Windows lie a little bit and allows you to ask for more memory than it actually has. And this white lie of Windows is called - Virtual Addressing.</strong><br></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!7mYB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2289c5c1-25a0-4430-814d-9a5a07472c48_500x500.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!7mYB!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2289c5c1-25a0-4430-814d-9a5a07472c48_500x500.jpeg 424w, https://substackcdn.com/image/fetch/$s_!7mYB!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2289c5c1-25a0-4430-814d-9a5a07472c48_500x500.jpeg 848w, https://substackcdn.com/image/fetch/$s_!7mYB!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2289c5c1-25a0-4430-814d-9a5a07472c48_500x500.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!7mYB!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2289c5c1-25a0-4430-814d-9a5a07472c48_500x500.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!7mYB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2289c5c1-25a0-4430-814d-9a5a07472c48_500x500.jpeg" width="500" height="500" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2289c5c1-25a0-4430-814d-9a5a07472c48_500x500.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:500,&quot;width&quot;:500,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:80286,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/jpeg&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!7mYB!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2289c5c1-25a0-4430-814d-9a5a07472c48_500x500.jpeg 424w, https://substackcdn.com/image/fetch/$s_!7mYB!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2289c5c1-25a0-4430-814d-9a5a07472c48_500x500.jpeg 848w, https://substackcdn.com/image/fetch/$s_!7mYB!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2289c5c1-25a0-4430-814d-9a5a07472c48_500x500.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!7mYB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2289c5c1-25a0-4430-814d-9a5a07472c48_500x500.jpeg 1456w" sizes="100vw"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><br>Windows will allow you to allocate, say 5 gigs of RAM in order to fire up two Chrome tabs (e.g. for GMail and LinkedIn) and it will happily provide you with memory space. But here&#8217;s the deal - <strong>some of those bits will end up on your hard drive</strong> (a process called &#8220;Paging Out&#8221;; more about it in future articles). So you keep working with these Virtual Addresses, thinking you have 5 gigs at disposal, but <strong>what happens in the background is that Operating System keeps juggling those bits back &amp; forth between actual RAM and your Hard Drive</strong>. Cool stuff!</p></li><li><p><strong>You can have contigous ranges of addresses </strong>&#8212; objectively speaking, there is NO way you&#8217;d ever get a contigous range of addresses from RAM, simply due to fragmentation that happens over time. So if you were working with ACTUAL physical addresses - that would be a no-go. Forget about integer arrays where next element is 4 bytes away from current one. Ain&#8217;t gonna work.<br><br>But when you use made-up addresses, you can do whatever the heck you want! So you ask for 2 gigs of RAM, and you get a 2 gigs contigous block back. In the background it&#8217;s 99% NOT contigous and some of it is likely sitting in your hard drive, but that&#8217;s somebody else&#8217;s problem!</p></li><li><p><strong>Stricter process isolation</strong> &#8212; just imagine a scenario where each process could write to any PHYSICAL memory address. You don&#8217;t have to be a security expert to see that a malicious process would try and scan the whole RAM immediately, right? I mean, sure, you could task your OS to track what belongs to whom, but once you end up in shared memory waters, shit becomes serious. And why bother?<br><br>If you provide each process with a virtual address space starting at 0x000 and going all the way to 0xFFF&#8230;FFFF, all you need to do is ensure to track the mappings of the process itself. Easy peasy (in a way!).</p></li></ol><p>Finally, and I know I haven&#8217;t introduced it officially yet (and I&#8217;ll do that in next articles!) but there are TWO modes of operation for each process in Windows. One is &#8220;User Mode&#8221; and another is &#8220;Kernel Mode&#8221;. User Mode is where all your user-started processes execute, whereas Kernel Mode is where all your drivers and Windows operate. Obviously, that&#8217;s oversimplification, but let&#8217;s assume it to be like that for now.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.bitesizedengineering.com/subscribe?"><span>Subscribe now</span></a></p><p>Difference between these two (again, an over-simplification!) is that each Process running in User Mode sees only it&#8217;s own Virtual Address space. Whichever memory location you ask for from inside the User process, Windows would see if you allocated that area and if you did - you&#8217;d get it back. If not - well, segmentation fault. Oh, and by the way - <strong>there&#8217;s NO way for user process to even ask for Virtual Addresses in Kernel space!</strong></p><p>On the other hand, processes running in System Mode (Kernel Mode, whatever), actually see a SINGLE &amp; UNIFORM Virtual Address space. They could ask for ANY address which, when mapped, could either be of a process running in user mode or could be of bits that were allocated by another process running in System Mode. Point being -<strong> anything running in System Mode can see and modify ANYTHING in the RAM!</strong></p><p>And that&#8217;d be about it for today :) I hope you found that useful, and if you did - I&#8217;d appreciate if you share it with your network!</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/p/virtual-adressing-and-why-every-process?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.bitesizedengineering.com/p/virtual-adressing-and-why-every-process?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p>Next time I will be talking about Virtual Memory functions and VirtualAlloc(). Until then!</p><div><hr></div><p>Other articles from the C++ Memory Management series:</p><ul><li><p><a href="https://www.bitesizedengineering.com/p/memory-allocation-through-heap-api">Memory allocation through Heap API</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/how-windows-allocates-memory">How Windows allocates memory</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/pointers-and-references-our-school">Pointers &amp; References - our school day boogeymans</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/why-does-memory-leak">Why does Memory Leak?</a></p></li></ul>]]></content:encoded></item><item><title><![CDATA[Memory allocation through Heap API]]></title><description><![CDATA[Chronicles of Memory Management - Part 11]]></description><link>https://www.bitesizedengineering.com/p/memory-allocation-through-heap-api</link><guid isPermaLink="false">https://www.bitesizedengineering.com/p/memory-allocation-through-heap-api</guid><dc:creator><![CDATA[Mihailo Joksimovic]]></dc:creator><pubDate>Fri, 24 Feb 2023 05:06:08 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!7aij!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1d59699-c02f-4ecb-bb1d-954c3aff5537_1600x4000.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hi there! &#128075;</p><p>First things first - I promised more articles this week but I barely managed to deliver two so far. I apologize. The thing is, if you care, that I had three conference talks to give (Wednesday, Thursday and Friday) and I simply presumed that I will manage to publish the articles in the night-hours. Well, what I didn&#8217;t count on was my son&#8217;s teething going crazy, virtually leaving us with no sleep at all :) So yep, I barely pulled this one and I&#8217;ll try pushing through one more on Sunday!</p><p>But that&#8217;s not what I wanted to talk about though. What I want to discuss today is Windows&#8217; Heap API. That magical thing that pretty much ANY language runtime eventually has to interact with. Be it C&#8217;s &#8220;malloc()&#8221;, C++&#8217;s &#8220;new&#8221;, Rust or .NET - they all interact with Windows via this API. So, let&#8217;s discuss it.</p><p>As usual, the bitesized graphic first and the more detailed explanation will follow below.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!7aij!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1d59699-c02f-4ecb-bb1d-954c3aff5537_1600x4000.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!7aij!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1d59699-c02f-4ecb-bb1d-954c3aff5537_1600x4000.png 424w, https://substackcdn.com/image/fetch/$s_!7aij!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1d59699-c02f-4ecb-bb1d-954c3aff5537_1600x4000.png 848w, https://substackcdn.com/image/fetch/$s_!7aij!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1d59699-c02f-4ecb-bb1d-954c3aff5537_1600x4000.png 1272w, https://substackcdn.com/image/fetch/$s_!7aij!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1d59699-c02f-4ecb-bb1d-954c3aff5537_1600x4000.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!7aij!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1d59699-c02f-4ecb-bb1d-954c3aff5537_1600x4000.png" width="1456" height="3640" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f1d59699-c02f-4ecb-bb1d-954c3aff5537_1600x4000.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:3640,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1105314,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!7aij!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1d59699-c02f-4ecb-bb1d-954c3aff5537_1600x4000.png 424w, https://substackcdn.com/image/fetch/$s_!7aij!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1d59699-c02f-4ecb-bb1d-954c3aff5537_1600x4000.png 848w, https://substackcdn.com/image/fetch/$s_!7aij!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1d59699-c02f-4ecb-bb1d-954c3aff5537_1600x4000.png 1272w, https://substackcdn.com/image/fetch/$s_!7aij!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1d59699-c02f-4ecb-bb1d-954c3aff5537_1600x4000.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>I hope that infographic gave you a clue? :)</p><p>One thing that you should be aware of is that the moment your process starts, you get 1MB of Stack and 1MB of Heap memory. What that further means is that if you can fit your Heap requirements in that 1MB, you should, theoretically, end up being way more performant than if you kept asking for more memory.</p><p>What&#8217;s cool to know is that you can override this behavior by providing the <a href="https://learn.microsoft.com/en-us/cpp/build/reference/heap?view=msvc-170">/LINK</a> directive to linker. If you know that your process will require, say, 5MBs to operate at it&#8217;s finest, then you should be good to go and ask for 5MB from the start.</p><p>What I find even more interesting is the sole reason of why would anyone use HeapAlloc instead of &#8220;new&#8221; or &#8220;malloc()&#8221;. And frankly, you probably shouldn&#8217;t, because default implementations are good enough for most cases.</p><p>HOWEVER, and this is really cool, by using Windows&#8217; native API for memory allocation you get access to some Windows-specific functionalities which simply can not be provided by generic implementations like &#8220;new&#8221; and &#8220;malloc()&#8221;. And two coolest things that you can do are:</p><ol><li><p>Create private Heaps, and</p></li><li><p>Pass some low-level flags (e.g. in order to disable serialization)</p></li></ol><p>You might be wondering why in the world would anyone want to have more than one heap, right? Isn&#8217;t one enough?</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.bitesizedengineering.com/subscribe?"><span>Subscribe now</span></a></p><p>One is enough. But having private ones really unlocks some cool things that I already mentioned in the graphic:</p><ol><li><p>You can create <strong>Memory Pools </strong>(i.e. heaps of fixed size) and allocate memory from there. Furthermore, you can overload the <a href="https://www.bitesizedengineering.com/p/what-happens-when-you-type-the-new">operator new</a> and place only specific objects on that private Heap, giving you a full control over WHERE they are and ensuring that you can remove them in one go by simply calling <a href="https://learn.microsoft.com/en-us/windows/win32/api/heapapi/nf-heapapi-heapdestroy">HeapDestroy()</a>.</p></li><li><p>Another cool thing you can do is have <strong>one Heap per thread</strong>. And if you are certain your heaps won&#8217;t need to share memory, there&#8217;s no need to have them wait for memory allocations (you are probably aware that &#8220;new&#8221; and &#8220;malloc()&#8221; are thread-safe and serialized, right?). By creating private Heaps and using the <a href="https://learn.microsoft.com/en-us/windows/win32/api/heapapi/nf-heapapi-heapcreate#parameters">HEAP_NO_SERIALIZE</a> flag you can ensure that each thread gets its bits immediately and without overlaps with others.</p></li><li><p>And finally, by allocating memory upfront, you can <strong>prevent memory fragmentation from happening</strong>. One typical example would be if you had a dynamically growing linked-list. The more time it passes between elements being added, the higher the chances are of those memory chunks ending up on different memory pages.</p></li></ol><p>Obviously, there&#8217;s a downside to all of this - now you have to add additional tracking and management for creating and destroying the heaps. But still, it all depends on the use-case.</p><p>And that would be about it for today. If you want to learn more about Heap API, I encourage you to check the <a href="https://learn.microsoft.com/en-us/windows/win32/api/heapapi/">official docs</a>.</p><p>Next time I&#8217;m going to talk a bit more about Memory API and VirtualAlloc, which is what gets called by HeapAlloc. Until then, if you enjoyed this article, I&#8217;d appreciate if you share it with your friends &amp; colleagues :)</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/p/memory-allocation-through-heap-api?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.bitesizedengineering.com/p/memory-allocation-through-heap-api?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p>Thanks for reading!</p><p>Mixa</p><div><hr></div><p>Other articles from the C++ Memory Management series:</p><ul><li><p><a href="https://www.bitesizedengineering.com/p/how-windows-allocates-memory">How Windows allocates memory</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/pointers-and-references-our-school">Pointers &amp; References - our school day boogeymans</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/why-does-memory-leak">Why does Memory Leak?</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/heaps-and-stacks-explained-like-youre-five">Heaps and Stacks - explained like you're five</a></p></li></ul>]]></content:encoded></item><item><title><![CDATA[How Windows allocates memory]]></title><description><![CDATA[Chronicles of Memory Management - Part 10]]></description><link>https://www.bitesizedengineering.com/p/how-windows-allocates-memory</link><guid isPermaLink="false">https://www.bitesizedengineering.com/p/how-windows-allocates-memory</guid><dc:creator><![CDATA[Mihailo Joksimovic]]></dc:creator><pubDate>Mon, 20 Feb 2023 06:01:10 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!Shae!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F90b7502f-8682-4fc8-9efb-dab85eb6a578_1600x4000.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Last week I mentioned I&#8217;m going to start focusing on Windows specific APIs for Memory Allocation. Well, the time has come to fullfil my promise :)</p><p>This article will pretty much try to answer the question I had a while ago - <strong>&#8220;what really happens (in Windows) when you type keyword &#8216;new&#8217;&#8221;</strong> (e.g. new CandyBar()). </p><p>As usual, the bite-sized graphic first and additional details below it.</p><p><em>(click on image to expand)</em></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Shae!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F90b7502f-8682-4fc8-9efb-dab85eb6a578_1600x4000.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Shae!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F90b7502f-8682-4fc8-9efb-dab85eb6a578_1600x4000.png 424w, https://substackcdn.com/image/fetch/$s_!Shae!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F90b7502f-8682-4fc8-9efb-dab85eb6a578_1600x4000.png 848w, https://substackcdn.com/image/fetch/$s_!Shae!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F90b7502f-8682-4fc8-9efb-dab85eb6a578_1600x4000.png 1272w, https://substackcdn.com/image/fetch/$s_!Shae!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F90b7502f-8682-4fc8-9efb-dab85eb6a578_1600x4000.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Shae!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F90b7502f-8682-4fc8-9efb-dab85eb6a578_1600x4000.png" width="1456" height="3640" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/90b7502f-8682-4fc8-9efb-dab85eb6a578_1600x4000.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:3640,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1100120,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Shae!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F90b7502f-8682-4fc8-9efb-dab85eb6a578_1600x4000.png 424w, https://substackcdn.com/image/fetch/$s_!Shae!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F90b7502f-8682-4fc8-9efb-dab85eb6a578_1600x4000.png 848w, https://substackcdn.com/image/fetch/$s_!Shae!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F90b7502f-8682-4fc8-9efb-dab85eb6a578_1600x4000.png 1272w, https://substackcdn.com/image/fetch/$s_!Shae!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F90b7502f-8682-4fc8-9efb-dab85eb6a578_1600x4000.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>As you see, both C++ and C (and I&#8217;d presume Rust and any other language runtime) eventually end up calling the <a href="https://learn.microsoft.com/en-us/windows/win32/api/heapapi/">Heap API</a> (strictly speaking, &#8220;keyword new&#8221; calls <a href="https://www.bitesizedengineering.com/p/what-happens-when-you-type-the-new">&#8220;operator new&#8221;</a> which in turn calls &#8220;malloc()&#8221; which eventually ends up calling &#8220;HeapAlloc&#8221;). <strong>Heap API is the main interface that Windows provides in order to allocate SINGLE BYTES</strong>.</p><p>Why do I say &#8220;Single Bytes&#8221;? Because once you go past the Heap API (i.e. once you go one level below) you end up in in <a href="https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-virtualalloc">VirtualAlloc</a> (i.e. <a href="https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/">Memory API</a>) which works in PAGES. What that means is that on this level you can only allocate MEMORY PAGES, which are ~4KBs in size.</p><p>If you&#8217;re not really familiar with Heap and Memory API, that&#8217;s totally fine. I will be digging deeper into them in the next articles!</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.bitesizedengineering.com/subscribe?"><span>Subscribe now</span></a></p><p>Now why is all of this important, interesting or relevant at all? Why in the god&#8217;s name would you ever interact with HeapAlloc or VirtualAlloc instead of using ol&#8217; good keyword new? And the truth is - if you&#8217;re asking this question, you likely won&#8217;t need to do it. But here&#8217;s the thing - C++ is built to run on ANY platform and that means that &#8220;new&#8221; has to be universal enough to be compileable for any underlying OS. Which further means that it has to be more on the generic side, which eventually means that it can&#8217;t provide support for some OS specific things and tweaks.</p><p>On the other hand, given the fact that HeapAlloc and VirtualAlloc are Windows-specific APIs, they support pretty much anything that you can ask Windows to do, some of those things being:</p><ol><li><p><a href="https://learn.microsoft.com/en-us/windows/win32/api/heapapi/">Heap API</a> allows you to create private Heaps and ask HeapAlloc to allocate bits from those places</p></li><li><p>You can disable thread-safety and serialized access by specifying the HEAP_NO_SERIALIZE flag</p></li><li><p><a href="https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-virtualalloc">Memory API&#8217;s VirtualAlloc</a> allows you even greater control - you can ask to RESERVE memory without committing it, you can do some tweaks on address ranges where memory is being reserved, etc.</p></li></ol><p>Generally speaking, possibilities are endless and you can pretty much fine-tune HOW you allocate the memory and make it fit your use-case. However, do remain mindful of the fact that with great power comes great responsibility.</p><p>Finally, in case you are wondering HOW you can actually see this in action - it&#8217;s quite simple. Fire up the Visual Studio, write some simple code that uses the &#8220;new&#8221; keyword (e.g. <code>int* foo = new int(10);</code>) set a breakpoint at that line, go to Disassembly window and just follow what happens:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!D-MY!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ed63740-5515-4eb3-89ef-8f308c4a7836_705x234.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!D-MY!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ed63740-5515-4eb3-89ef-8f308c4a7836_705x234.png 424w, https://substackcdn.com/image/fetch/$s_!D-MY!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ed63740-5515-4eb3-89ef-8f308c4a7836_705x234.png 848w, https://substackcdn.com/image/fetch/$s_!D-MY!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ed63740-5515-4eb3-89ef-8f308c4a7836_705x234.png 1272w, https://substackcdn.com/image/fetch/$s_!D-MY!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ed63740-5515-4eb3-89ef-8f308c4a7836_705x234.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!D-MY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ed63740-5515-4eb3-89ef-8f308c4a7836_705x234.png" width="705" height="234" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3ed63740-5515-4eb3-89ef-8f308c4a7836_705x234.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:234,&quot;width&quot;:705,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:22373,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!D-MY!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ed63740-5515-4eb3-89ef-8f308c4a7836_705x234.png 424w, https://substackcdn.com/image/fetch/$s_!D-MY!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ed63740-5515-4eb3-89ef-8f308c4a7836_705x234.png 848w, https://substackcdn.com/image/fetch/$s_!D-MY!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ed63740-5515-4eb3-89ef-8f308c4a7836_705x234.png 1272w, https://substackcdn.com/image/fetch/$s_!D-MY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ed63740-5515-4eb3-89ef-8f308c4a7836_705x234.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Operator new gets called</figcaption></figure></div><p></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!My9e!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98b4fa42-62c2-4db2-b0b4-5c40497ff9eb_552x206.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!My9e!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98b4fa42-62c2-4db2-b0b4-5c40497ff9eb_552x206.png 424w, https://substackcdn.com/image/fetch/$s_!My9e!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98b4fa42-62c2-4db2-b0b4-5c40497ff9eb_552x206.png 848w, https://substackcdn.com/image/fetch/$s_!My9e!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98b4fa42-62c2-4db2-b0b4-5c40497ff9eb_552x206.png 1272w, https://substackcdn.com/image/fetch/$s_!My9e!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98b4fa42-62c2-4db2-b0b4-5c40497ff9eb_552x206.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!My9e!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98b4fa42-62c2-4db2-b0b4-5c40497ff9eb_552x206.png" width="552" height="206" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/98b4fa42-62c2-4db2-b0b4-5c40497ff9eb_552x206.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:206,&quot;width&quot;:552,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:18157,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!My9e!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98b4fa42-62c2-4db2-b0b4-5c40497ff9eb_552x206.png 424w, https://substackcdn.com/image/fetch/$s_!My9e!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98b4fa42-62c2-4db2-b0b4-5c40497ff9eb_552x206.png 848w, https://substackcdn.com/image/fetch/$s_!My9e!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98b4fa42-62c2-4db2-b0b4-5c40497ff9eb_552x206.png 1272w, https://substackcdn.com/image/fetch/$s_!My9e!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98b4fa42-62c2-4db2-b0b4-5c40497ff9eb_552x206.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Operator new calls malloc()</figcaption></figure></div><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Cs0H!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01dfddd9-b1a5-4f4f-9f68-67f20fc5f6ef_689x324.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Cs0H!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01dfddd9-b1a5-4f4f-9f68-67f20fc5f6ef_689x324.png 424w, https://substackcdn.com/image/fetch/$s_!Cs0H!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01dfddd9-b1a5-4f4f-9f68-67f20fc5f6ef_689x324.png 848w, https://substackcdn.com/image/fetch/$s_!Cs0H!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01dfddd9-b1a5-4f4f-9f68-67f20fc5f6ef_689x324.png 1272w, https://substackcdn.com/image/fetch/$s_!Cs0H!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01dfddd9-b1a5-4f4f-9f68-67f20fc5f6ef_689x324.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Cs0H!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01dfddd9-b1a5-4f4f-9f68-67f20fc5f6ef_689x324.png" width="689" height="324" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/01dfddd9-b1a5-4f4f-9f68-67f20fc5f6ef_689x324.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:324,&quot;width&quot;:689,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:30791,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Cs0H!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01dfddd9-b1a5-4f4f-9f68-67f20fc5f6ef_689x324.png 424w, https://substackcdn.com/image/fetch/$s_!Cs0H!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01dfddd9-b1a5-4f4f-9f68-67f20fc5f6ef_689x324.png 848w, https://substackcdn.com/image/fetch/$s_!Cs0H!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01dfddd9-b1a5-4f4f-9f68-67f20fc5f6ef_689x324.png 1272w, https://substackcdn.com/image/fetch/$s_!Cs0H!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01dfddd9-b1a5-4f4f-9f68-67f20fc5f6ef_689x324.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">malloc() calls heap_alloc</figcaption></figure></div><p></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!RHKy!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8870e13-bc73-41c5-b597-283bfd31103d_961x170.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!RHKy!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8870e13-bc73-41c5-b597-283bfd31103d_961x170.png 424w, https://substackcdn.com/image/fetch/$s_!RHKy!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8870e13-bc73-41c5-b597-283bfd31103d_961x170.png 848w, https://substackcdn.com/image/fetch/$s_!RHKy!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8870e13-bc73-41c5-b597-283bfd31103d_961x170.png 1272w, https://substackcdn.com/image/fetch/$s_!RHKy!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8870e13-bc73-41c5-b597-283bfd31103d_961x170.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!RHKy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8870e13-bc73-41c5-b597-283bfd31103d_961x170.png" width="961" height="170" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e8870e13-bc73-41c5-b597-283bfd31103d_961x170.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:170,&quot;width&quot;:961,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:20391,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!RHKy!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8870e13-bc73-41c5-b597-283bfd31103d_961x170.png 424w, https://substackcdn.com/image/fetch/$s_!RHKy!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8870e13-bc73-41c5-b597-283bfd31103d_961x170.png 848w, https://substackcdn.com/image/fetch/$s_!RHKy!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8870e13-bc73-41c5-b597-283bfd31103d_961x170.png 1272w, https://substackcdn.com/image/fetch/$s_!RHKy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8870e13-bc73-41c5-b597-283bfd31103d_961x170.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">heap_alloc eventually calls HeapAlloc()</figcaption></figure></div><p> And that&#8217;s about it. Go try and experiment with it!</p><p>Next time I&#8217;m going to talk more about Heap API and HeapAlloc. Until then, do let me know if you found this article useful. You&#8217;d also help me if you spread the word by sharing it with your friends and colleagues:</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.bitesizedengineering.com/p/how-windows-allocates-memory?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.bitesizedengineering.com/p/how-windows-allocates-memory?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p>Thanks for reading!</p><div><hr></div><p>Other articles from the C++ Memory Management series:</p><ul><li><p><a href="https://www.bitesizedengineering.com/p/pointers-and-references-our-school">Pointers &amp; References - our school day boogeymans</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/why-does-memory-leak">Why does Memory Leak?</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/heaps-and-stacks-explained-like-youre-five">Heaps and Stacks - explained like you're five</a></p></li><li><p><a href="https://www.bitesizedengineering.com/p/what-happens-when-you-type-the-new">What happens when you type the "new" keyword?</a></p></li></ul><p></p>]]></content:encoded></item></channel></rss>