<?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[Maneesh’s Substack]]></title><description><![CDATA[Documenting What I Learn]]></description><link>https://maneeshsagar.substack.com</link><image><url>https://substackcdn.com/image/fetch/$s_!UA4v!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35fe1ee4-6af6-411f-b6c0-4a71a22d1d5a_144x144.png</url><title>Maneesh’s Substack</title><link>https://maneeshsagar.substack.com</link></image><generator>Substack</generator><lastBuildDate>Thu, 20 Aug 2026 05:11:12 GMT</lastBuildDate><atom:link href="https://maneeshsagar.substack.com/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[Maneesh Sagar]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[maneeshsagar@substack.com]]></webMaster><itunes:owner><itunes:email><![CDATA[maneeshsagar@substack.com]]></itunes:email><itunes:name><![CDATA[Maneesh Sagar]]></itunes:name></itunes:owner><itunes:author><![CDATA[Maneesh Sagar]]></itunes:author><googleplay:owner><![CDATA[maneeshsagar@substack.com]]></googleplay:owner><googleplay:email><![CDATA[maneeshsagar@substack.com]]></googleplay:email><googleplay:author><![CDATA[Maneesh Sagar]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[Reflection Pattern of Agent]]></title><description><![CDATA[An Introduction to Reflection in AI Agent Design]]></description><link>https://maneeshsagar.substack.com/p/reflection-pattern-of-agent</link><guid isPermaLink="false">https://maneeshsagar.substack.com/p/reflection-pattern-of-agent</guid><dc:creator><![CDATA[Maneesh Sagar]]></dc:creator><pubDate>Sat, 01 Aug 2026 18:07:49 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!ZxYc!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c639bfa-7a65-4e6d-b2c2-794ebdc40fb6_1918x510.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Reflection is an agentic design pattern in which a model (or another reviewer) critiques an initial output and uses that feedback to generate an improved version. The reflection loop continues until the output satisfies predefined criteria or a maximum number of iterations is reached.  LLMs rarely produce the best answer on the first attempt. Reflection gives an opportunity to identify the mistakes and gaps before the revised response.</p><p>We can understand this in two ways.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://maneeshsagar.substack.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 Maneesh&#8217;s Substack! 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><h4>Objective feedback </h4><p>In objective evaluation, an external system verifies whether the generated output is correct.</p><h5>Coding agent</h5><p>Let's suppose we are building a Python code generator that generates functions for a  given task</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ZxYc!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c639bfa-7a65-4e6d-b2c2-794ebdc40fb6_1918x510.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ZxYc!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c639bfa-7a65-4e6d-b2c2-794ebdc40fb6_1918x510.png 424w, https://substackcdn.com/image/fetch/$s_!ZxYc!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c639bfa-7a65-4e6d-b2c2-794ebdc40fb6_1918x510.png 848w, https://substackcdn.com/image/fetch/$s_!ZxYc!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c639bfa-7a65-4e6d-b2c2-794ebdc40fb6_1918x510.png 1272w, https://substackcdn.com/image/fetch/$s_!ZxYc!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c639bfa-7a65-4e6d-b2c2-794ebdc40fb6_1918x510.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ZxYc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c639bfa-7a65-4e6d-b2c2-794ebdc40fb6_1918x510.png" width="1456" height="387" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6c639bfa-7a65-4e6d-b2c2-794ebdc40fb6_1918x510.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:387,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:58576,&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;:&quot;https://maneeshsagar.substack.com/i/209282549?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c639bfa-7a65-4e6d-b2c2-794ebdc40fb6_1918x510.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ZxYc!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c639bfa-7a65-4e6d-b2c2-794ebdc40fb6_1918x510.png 424w, https://substackcdn.com/image/fetch/$s_!ZxYc!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c639bfa-7a65-4e6d-b2c2-794ebdc40fb6_1918x510.png 848w, https://substackcdn.com/image/fetch/$s_!ZxYc!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c639bfa-7a65-4e6d-b2c2-794ebdc40fb6_1918x510.png 1272w, https://substackcdn.com/image/fetch/$s_!ZxYc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c639bfa-7a65-4e6d-b2c2-794ebdc40fb6_1918x510.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 aria-hidden="true" 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><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>Just see the image above that shows a coding agent that generates code v1 in the first pass; then the runner runs the code. If any error comes, then with the error and code v1 passes to the LLM again, based on the feedback, produce a result again, and so on until the code runs or to max iterations.</p><h4>Subjective feedback example </h4><h5>An agent that writes an essay</h5><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!MYJi!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde7801f8-75bc-4622-840d-f5cb062230c5_1202x572.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!MYJi!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde7801f8-75bc-4622-840d-f5cb062230c5_1202x572.png 424w, https://substackcdn.com/image/fetch/$s_!MYJi!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde7801f8-75bc-4622-840d-f5cb062230c5_1202x572.png 848w, https://substackcdn.com/image/fetch/$s_!MYJi!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde7801f8-75bc-4622-840d-f5cb062230c5_1202x572.png 1272w, https://substackcdn.com/image/fetch/$s_!MYJi!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde7801f8-75bc-4622-840d-f5cb062230c5_1202x572.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!MYJi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde7801f8-75bc-4622-840d-f5cb062230c5_1202x572.png" width="1202" height="572" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/de7801f8-75bc-4622-840d-f5cb062230c5_1202x572.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:572,&quot;width&quot;:1202,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:60436,&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;:&quot;https://maneeshsagar.substack.com/i/209282549?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde7801f8-75bc-4622-840d-f5cb062230c5_1202x572.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!MYJi!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde7801f8-75bc-4622-840d-f5cb062230c5_1202x572.png 424w, https://substackcdn.com/image/fetch/$s_!MYJi!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde7801f8-75bc-4622-840d-f5cb062230c5_1202x572.png 848w, https://substackcdn.com/image/fetch/$s_!MYJi!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde7801f8-75bc-4622-840d-f5cb062230c5_1202x572.png 1272w, https://substackcdn.com/image/fetch/$s_!MYJi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde7801f8-75bc-4622-840d-f5cb062230c5_1202x572.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 aria-hidden="true" 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><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>In this case, the reviewer or critic is an LLM, not any external tool; the input reviewer could be the same model(self), some other model, or a human.</p><h4> Eval methods to evaluate the reflections</h4><h5>Objective Evals</h5><p>We prepare a benchmark dataset containing inputs and expected outputs; if that passes, we consider the agent is ready. </p><p>e.g.</p><ol><li><p>Above code-based example</p></li><li><p>Build a dataset and evaluate on that (SQL): We create an agent that generates the SQL queries.</p></li></ol><h5>Subjective Evals</h5><p>Since quality is subjective, we provide the evaluator with clear evaluation criteria or a rubric so that it reviews the response consistently.</p><p>e.g.</p><ol><li><p>Use an LLM as a guide to evaluate</p></li><li><p>Rubric-based, where you would define the rules step by step </p></li></ol><p></p><p>Ref: Andrew Ng course</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://maneeshsagar.substack.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 Maneesh&#8217;s Substack! 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[Story Of Cryptography ]]></title><description><![CDATA[Representation of symmetric and asymmetric cryptography through small story]]></description><link>https://maneeshsagar.substack.com/p/story-of-cryptography</link><guid isPermaLink="false">https://maneeshsagar.substack.com/p/story-of-cryptography</guid><dc:creator><![CDATA[Maneesh Sagar]]></dc:creator><pubDate>Sat, 03 Jan 2026 14:30:31 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!UA4v!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35fe1ee4-6af6-411f-b6c0-4a71a22d1d5a_144x144.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>I told my girlfriend you can&#8217;t do this to me. She told me I won&#8217;t accept or send any letter anymore. I used to send her a letter via her friend and she did the same. But after a few days her friend started reading our letter and started teasing her. So I started adding 2 indexes in every alphabet letter (I write <strong>a</strong> as <strong>c, b</strong> as <strong>d, c</strong> as <strong>e</strong> and so on) sometimes I add <strong>2</strong> sometimes <strong>4</strong> sometimes any number and I used to write that number on that letter too and she did the same. But after a few days her friend cracked that too and she got to know that we are writing keys on letters her friend used to decode. Then we were stuck on what to do now. Then I found one more way there in the market. There was a pair of (Pen and Spectacle ) If you write anything with that pen so a person who has that Spectacle can see the text written. So we bought two pairs and exchanged pens with each other. Now we can clearly and without any problem we can communicate with each other.</p><p>The first mode of communication is called <strong>symmetric</strong> cryptography where a single key is shared between two parties, the same key is used to encrypt and decrypt.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://maneeshsagar.substack.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 Maneesh&#8217;s Substack! 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>Symmetric Methods are <strong>AES, DES</strong>.</p><p>The second mode of encryption is called <strong>asymmetric</strong> cryptography in which <strong>public key, private keys are </strong>used<strong>. </strong>A public key is used to encrypt the data and the person who will have a private key will be able to read the message.</p><p>Asymmetric Methods are <strong>RSA, ECC.</strong></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://maneeshsagar.substack.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 Maneesh&#8217;s Substack! 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[Memory Management in Rust]]></title><description><![CDATA[This article is about exploring the Rust memory model. How does rust manage the memory?]]></description><link>https://maneeshsagar.substack.com/p/memory-management-in-rust</link><guid isPermaLink="false">https://maneeshsagar.substack.com/p/memory-management-in-rust</guid><dc:creator><![CDATA[Maneesh Sagar]]></dc:creator><pubDate>Sat, 09 Aug 2025 18:25:12 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!UA4v!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35fe1ee4-6af6-411f-b6c0-4a71a22d1d5a_144x144.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>As mentioned in previous <a href="https://maneeshsagar.substack.com/p/how-memory-allocation-works-in-modern">article</a> what are different ways, programming languages use to manage memory. As a programmer we know that heap is the memory section where most of the complexity and potential problems arise. In almost all programming languages stack and other memory section behave similarly but heap management differs significantly from language to language.</p><p>Rust take a very unique approach to manage the heap memory but before that let&#8217;s first look how allocation and deallocation are generally handled and then explore the rust model</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://maneeshsagar.substack.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 Maneesh&#8217;s Substack! 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><h4>Allocation</h4><p>Internally, Rust uses <strong>system allocator</strong> to allocate the memory, just like <strong>new</strong> in <strong>C++, Go, Java </strong>and <strong>malloc, calloc</strong> in <strong>C.</strong></p><pre><code><strong>In Rust</strong>
let obj:Box&lt;String&gt; = Box::new();

<strong>In C++</strong>
int* ptr = new int(42);

<strong>In C</strong>
int *ptr=(int*)malloc(sizeof(int)*5);

<strong>in JAVA</strong>
String name = new String("Hello");

<strong>In Go</strong>
mp:=make(map[string]string)</code></pre><h4>Deallocation</h4><p>In <strong>C</strong> and <strong>C++</strong> programmer has to deallocate the memory, In <strong>Java</strong> and <strong>Go</strong> <strong>Garbage collector</strong> deallocates the memory from heap.</p><p>But Rust uses very unique approaches to deallocate the heap memory; when a variable&#8217;s  scope ends it calls <strong>drop</strong> function and cleans up the heap memory. This is made possible by <strong>ownership</strong> which is a set of rules enforced <strong>at compile time</strong>. There&#8217;s no <strong>garbage collector</strong> in Rust; instead, <strong>Ownership, Borrowing, and Lifetimes</strong> ensure memory safety without runtime overhead. let discuss these concepts in detail.</p><h5>Ownership</h5><p>This is the concept which enforces that one value in memory will have only one owner at a time. As the owner go out of scope automatically free the memory and no need of <strong>garbage collection.</strong></p><p>This guarantees:</p><ul><li><p>No <strong>double frees</strong></p></li><li><p>No <strong>use-after-free</strong></p></li><li><p>Automatic cleanup</p></li></ul><pre><code><strong>let owner1:String=String::from("Hello");</strong>

here owner1 is owner of string <strong>Hello

let owner2=owner1;</strong>

now <strong>owner2</strong> is owner of the string <strong>Hello</strong> and using <strong>owner1</strong> you can't perform any kind of operation like push etc.</code></pre><h5>Borrowing</h5><p>When you have a value in Rust, it&#8217;s owned by exactly one variable. If you want to let other parts of your code access it <strong>without moving ownership</strong>, you borrow it.</p><p>Borrowing is how Rust ensures:</p><ul><li><p>No <strong>dangling pointers</strong></p></li><li><p>No <strong>data races</strong> (even in multithreaded code)</p></li><li><p>Memory is freed exactly once</p></li></ul><p>There are two types of borrowing</p><ul><li><p>Mutable: Can modify the value but at a time only one mutable borrowing is possible.</p><pre><code>let mut s = String::from("Maneesh");
let r1 = &amp;mut s;
// let r2 = &amp;mut s; // you will get compilation error</code></pre></li></ul><ul><li><p>Immutable: read only access to the memory</p><pre><code>let s = String::from("Maneesh");
let a = &amp;s;
let b = &amp;s; 
println!("{}, {}", a, b);</code></pre></li></ul><h5>Lifetime</h5><p>When reference is passed at that time compiler has to know that when the owner of referenced memory will be invalid or go out of the scope. Reference should not outlive that can cause dangling pointer that&#8217;s how rust ensure memory safety.</p><pre><code> fn longest&lt;'a&gt;(s1: &amp;'a str, s2: &amp;'a str) -&gt; &amp;'a str {
    if s1.len() &gt; s2.len(){ 
           s1 
          } else { 
           s2
       }
}</code></pre><p>&#8216;a is the life time expression, input and output must live at least as long as &#8216;a is live. Every reference has lifetime explicit or implicit, lifetime only needed when compiler can&#8217;t infer. It is also checked at compile time so no runtime overhead.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://maneeshsagar.substack.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 Maneesh&#8217;s Substack! 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[How Memory Allocation Works in Modern Programming?]]></title><description><![CDATA[This article presents a subtle yet insightful comparison of memory allocation and deallocation strategies across different types of programming languages]]></description><link>https://maneeshsagar.substack.com/p/how-memory-allocation-works-in-modern</link><guid isPermaLink="false">https://maneeshsagar.substack.com/p/how-memory-allocation-works-in-modern</guid><dc:creator><![CDATA[Maneesh Sagar]]></dc:creator><pubDate>Sun, 03 Aug 2025 18:04:22 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!VWIn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff9bf020-f48a-4230-89e4-07a3ef218f3b_1300x1412.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h4>How a program looks like in RAM?</h4><p>When a compiled/executable program gets loaded in memory it becomes a process and operating systems manages all relevent  process information like process id, process state etc. into the Process Control Block(PCB). A typical process in memory is divided into the following major segments</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!VWIn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff9bf020-f48a-4230-89e4-07a3ef218f3b_1300x1412.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!VWIn!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff9bf020-f48a-4230-89e4-07a3ef218f3b_1300x1412.png 424w, https://substackcdn.com/image/fetch/$s_!VWIn!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff9bf020-f48a-4230-89e4-07a3ef218f3b_1300x1412.png 848w, https://substackcdn.com/image/fetch/$s_!VWIn!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff9bf020-f48a-4230-89e4-07a3ef218f3b_1300x1412.png 1272w, https://substackcdn.com/image/fetch/$s_!VWIn!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff9bf020-f48a-4230-89e4-07a3ef218f3b_1300x1412.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!VWIn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff9bf020-f48a-4230-89e4-07a3ef218f3b_1300x1412.png" width="1300" height="1412" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ff9bf020-f48a-4230-89e4-07a3ef218f3b_1300x1412.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1412,&quot;width&quot;:1300,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:436146,&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;:&quot;https://maneeshsagar.substack.com/i/169485221?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff9bf020-f48a-4230-89e4-07a3ef218f3b_1300x1412.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!VWIn!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff9bf020-f48a-4230-89e4-07a3ef218f3b_1300x1412.png 424w, https://substackcdn.com/image/fetch/$s_!VWIn!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff9bf020-f48a-4230-89e4-07a3ef218f3b_1300x1412.png 848w, https://substackcdn.com/image/fetch/$s_!VWIn!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff9bf020-f48a-4230-89e4-07a3ef218f3b_1300x1412.png 1272w, https://substackcdn.com/image/fetch/$s_!VWIn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff9bf020-f48a-4230-89e4-07a3ef218f3b_1300x1412.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 aria-hidden="true" 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><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><h5>Code/Text Segment</h5><ul><li><p>Contains the compiled executable machine code. </p></li><li><p>This is read only section to prevent accidental modification. </p></li><li><p>This section can be shared with the other instances of the same program for saving resource. </p></li></ul><h5>Data Section</h5><ul><li><p>This section stores the all static and global variables. </p></li><li><p>It&#8217;s a read-write section.</p></li><li><p>It's further divided into:</p><ul><li><p><strong>Initialized data</strong> (variables with explicit initial values)</p></li><li><p><strong>Uninitialized data (BSS)</strong> (variables that are zero-initialized by default)</p></li></ul></li></ul><h5>Stack</h5><ul><li><p>This is the section where all local variable and function parameter return address on function get stored. </p></li><li><p>It operates in Last in First out manner it grows towards the lower memory address.</p></li><li><p>Managed automatically by runtime.</p></li></ul><h5>Heap</h5><ul><li><p>This is used for dynamic memory allocation(object which size is not known at compile time get stored here like vector, string, map etc.) </p></li><li><p>Grows upward towards the higher memory address.</p></li><li><p>It is managed by programmer in C, CPP and by runtime in Go and JAVA.</p></li><li><p>Our most of the discussion will be around the heap memory because most of the problem comes in heap.</p></li></ul><h4>How memory get allocated &amp; deallocated?</h4><ul><li><p>In C, when we write <strong>malloc() </strong>it allocates memory in heap and when we use <strong>free()</strong>, then frees the memory. </p></li><li><p>In <strong>Java</strong> or <strong>Go </strong>just use the <strong>make()</strong> or <strong>new </strong>and do not care about the either memory allocation or deallocation, runtime and <strong>Garbage collector(CG) </strong>take care about the memory allocation and deallocation. but it comes with some cost. </p></li><li><p>And then <strong>Rust</strong> came in the picture with the complete new memory model which enforces deterministic deallocation via <strong>ownership</strong>, <strong>borrowing</strong> and <strong>lifetime</strong> whenever the scope of the function over then memory allocated in heap also get deallocated without involving <strong>GC.</strong></p></li></ul><p>we can say that now we have three types of programming language First in which programmer has to allocate and deallocate the heap memory. Second one is which allocation will taken care by runtime and deallocation will be taken care by GC. Third one in which allocation will taken care by runtime but heap memory is freed <strong>automatically and deterministically</strong> when the owner goes out of scope so no manual or no GC.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://maneeshsagar.substack.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 Maneesh&#8217;s Substack! 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[Difference between new() and make() in Go Lang]]></title><description><![CDATA[There are two built-in function in Go to allocate the memory new() and make() both works on different type and do different work.]]></description><link>https://maneeshsagar.substack.com/p/difference-between-new-and-make-in</link><guid isPermaLink="false">https://maneeshsagar.substack.com/p/difference-between-new-and-make-in</guid><dc:creator><![CDATA[Maneesh Sagar]]></dc:creator><pubDate>Tue, 21 May 2024 20:31:36 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!UA4v!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35fe1ee4-6af6-411f-b6c0-4a71a22d1d5a_144x144.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://maneeshsagar.substack.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://maneeshsagar.substack.com/subscribe?"><span>Subscribe now</span></a></p><p>There are two built-in function in Go to allocate the memory <strong>new()</strong> and <strong>make() </strong>both works on different type and do different work. Knowing the difference between is must to write the clean code.</p><h3>1. What new() function does and where to use ?</h3><p>It only allocates zeroed memory but does not initialize the memory. It returns the pointer(address) to the allocated memory.</p><pre><code><code>var price1 *int

price2:= new(int)</code></code></pre><p>both <strong>price1</strong> and price are of similar type but <strong>price2</strong> has allocated zeroed memory but <strong>price1</strong> is not having any memory.</p><pre><code><code>type Car struct {

 Type string

 Number string

}

func main() {

 car1 := new(Car) 

 car2 := &amp;Car{}

 fmt.Println(car1)

 fmt.Println(car2)

}</code></code></pre><p>car1 and car2 is of similar type, we can conclude that </p><h3>2. What make() function does and where to use ?</h3><p>It is used to allocated the memory and initalize int internal data structure needed for  the map, channel, slices and returns the value of these type.</p><pre><code>s := make([]int, 10, 15) 
m := make(map[string]int)
c := make(chan int, 5)</code></pre><h3>3. Comparison</h3><pre><code> s := make([]int, 10, 15)    // Creates a slice with length 10 and capacity 15
         
p := new([]int) // Allocates memory for a slice pointer, but the slice is nil
        
fmt.Println(*p) // Prints []

*p = make([]int, 10, 15) // To initialize the slice pointed by p, you'd need to use make
fmt.Println(*p) // Prints [0 0 0 0 0 0 0 0 0 0] </code></pre><h3>5. Conculsion</h3><p>We can conlude that <strong>new()</strong> is more generic  while <strong>make() </strong>can be used only for the map, slices and channels.</p><div><hr></div><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://maneeshsagar.substack.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 Maneesh&#8217;s Substack! 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></p>]]></content:encoded></item></channel></rss>