<?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:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Prachiti Parkar on Medium]]></title>
        <description><![CDATA[Stories by Prachiti Parkar on Medium]]></description>
        <link>https://medium.com/@psparkar_b16?source=rss-2031054fd437------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*_eWK4lFbMLlLyIucO4bk9w.jpeg</url>
            <title>Stories by Prachiti Parkar on Medium</title>
            <link>https://medium.com/@psparkar_b16?source=rss-2031054fd437------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 11:28:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@psparkar_b16/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Mumma… I’m in the newspaper]]></title>
            <link>https://medium.com/@psparkar_b16/mumma-im-in-the-newspaper-aaa3f77be7c4?source=rss-2031054fd437------2</link>
            <guid isPermaLink="false">https://medium.com/p/aaa3f77be7c4</guid>
            <category><![CDATA[newspapers]]></category>
            <category><![CDATA[viral]]></category>
            <category><![CDATA[microsoft]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[trending]]></category>
            <dc:creator><![CDATA[Prachiti Parkar]]></dc:creator>
            <pubDate>Thu, 30 Jul 2026 18:02:24 GMT</pubDate>
            <atom:updated>2026-07-30T18:02:24.201Z</atom:updated>
            <content:encoded><![CDATA[<p>Something totally out of the blue happened yesterday, I was just getting out of my bed and like most of us, I have a bad habit of checking my social media to wake me up. I randomly checked my inbox on X and I saw that a journalist has sent me a link to an article about me on <a href="https://www.hindustantimes.com/trending/us/techie-shares-how-microsoft-india-rejection-led-her-to-microsofts-us-office-what-a-journey-101785322702842.html"><strong><em>Hindustan Times</em></strong></a><strong><em>.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*62lsfQVSNjeXpkG-Irn8Hg.png" /><figcaption>An article on me in Hindustan Times</figcaption></figure><p>This was absolutely crazy, and I did <strong>not</strong> see it coming. Let’s rewind by a day. I’m pretty active on Twitter (yes, I’m still calling it Twitter — I refuse to call it X. It just doesn’t have the same vibes ), and being the oversharing girl that I am, I posted about taking my parents to my workplace.</p><p>To my surprise, the tweet took off. It had already crossed <strong>16K views in a day</strong>. Later that day, I randomly checked my message requests and saw a DM from a journalist asking if she could feature my story in <em>Hindustan Times</em>. Now, this wasn’t the first time something like this had happened. I’ve received similar requests before, happily said yes, and then… complete radio silence.</p><p>So I assumed this would be another one of those.</p><p>Except this time, it actually happened.</p><p>So, what’s the story that actually went viral? Was it really just that four-line tweet? If that were the whole story, I probably wouldn’t be writing this. 😄</p><p>Let’s go back to 2022. By then, I had already received offers from Morgan Stanley and Amazon, and I was incredibly grateful for both. But Microsoft was… different.</p><p>It wasn’t just another company on my wishlist — it was <strong>the</strong> dream. Whenever someone asked me where I wanted to work, my answer was always the same: Microsoft or Google. Microsoft, though, always had a special place in my heart. I’ve admired Satya Nadella for years. Watching him transform a company that many had written off into one that’s now worth nearly <strong>$3.5 trillion</strong> has been nothing short of incredible. Honestly, that’s a story deserving of its own post because I could probably spend hours fangirling over his leadership. I remember reading his blogs on Azure, following his vision for cloud computing, and being fascinated by where he was taking the company. Long before I ever interviewed at Microsoft, I knew that if I ever had the chance to work there, I’d take it in a heartbeat.</p><p>I still remember getting that first Microsoft recruiter call.</p><p>I told my mom, <em>“If I crack this, I’m going to Bengaluru instead of the US.”</em> And this was <strong>before</strong> I even knew the compensation. For me, this opportunity was bigger than money. Working at Microsoft had always been one of those dreams that just felt… different.</p><p>The interview process was fairly standard — two LeetCode rounds. The recruiter told me that if I cleared them, I was basically in.</p><p>The first one went great. The second? Not so much. I walked out of it convinced I had blown my chance. I had already started preparing myself for the rejection.</p><p>Then the recruiter called.</p><blockquote><em>“It wasn’t as bad as you think. There’s going to be one final round.”</em></blockquote><p>One last chance. Except this interview was nothing like I expected. Instead of jumping into coding, the interviewer gave me a deliberately vague problem. He expected me to ask clarifying questions, uncover the real problem, and then solve it. I did exactly… none of that.</p><p>I started coding almost immediately, completely missing what he was actually evaluating. A few days later, the rejection came.</p><p>That was it, I thought.</p><p>I packed my bags, boarded a flight to Boston, and convinced myself that this chapter was over.</p><p>Fast forward to 2025.</p><p>I was happily working at Nutanix when, out of nowhere, an engineering manager from Azure Storage reached out to me.</p><p>I hadn’t even applied. I remember thinking, <em>“I have got another chance, I need to get this.”</em></p><p>I went through another marathon of interviews — four or five rounds this time — and finally got the offer. I had made it.</p><p>Except… I couldn’t join. Visa issues got in the way. It was probably one of the most frustrating moments of my career. After getting so close, something completely outside my control stopped me.</p><p>Then came 2026. I decided to reach out again. To my surprise, they remembered me.Even during a hiring freeze, they were willing to interview me. This time, there was just one interview.</p><blockquote>I cleared it. And finally…I was in.</blockquote><p>Even after signing the offer, a small part of me refused to believe it. I kept expecting something to go wrong. It wasn’t until I walked onto the Microsoft campus on my very first day that it finally sank in. This wasn’t just another job. It was a dream that had taken multiple interviews, a rejection, a visa setback, and nearly four years to become reality. Sometimes the path to your dream company isn’t a straight line. Mine definitely wasn’t.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/1*A5W2SmOozJixmK0g2_5oCg.png" /><figcaption>That’s my name on my cabin door.</figcaption></figure><p>I read that one ‘NO’ cannot define your potential, but today I am living it.</p><p>Follow me for more such stories — whether it’s distributed systems, tech lessons, career journeys, or sometimes just a girl ranting about her everyday life. 😄</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aaa3f77be7c4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Episode2: Paper Notes for FastCommit]]></title>
            <link>https://medium.com/@psparkar_b16/episode2-paper-notes-for-fastcommit-be9aff55180b?source=rss-2031054fd437------2</link>
            <guid isPermaLink="false">https://medium.com/p/be9aff55180b</guid>
            <category><![CDATA[data-storage]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[storage]]></category>
            <dc:creator><![CDATA[Prachiti Parkar]]></dc:creator>
            <pubDate>Mon, 13 Oct 2025 04:49:04 GMT</pubDate>
            <atom:updated>2025-10-13T04:49:04.724Z</atom:updated>
            <content:encoded><![CDATA[<p>Welcome to Episode 2 of my Distributed Systems Paper Reading Series, where we dive into FastCommit — a smarter, faster approach to journaling in file systems<em>.</em><br>This blog is structured into 2 parts — the first section would cover most of the jargon/concepts required to understand the paper and the rest would cover the potential takeaways of this paper.</p><p>Today, we are talking about FastCommit: resource-efficient, performant and cost-effective file system journaling.</p><p>What is <strong>journaling</strong>?<br><em>Journaling</em>, also known as Write-Ahead Logging (WAL), a fault-tolerance technique that records data to a log before persisting it to disk. Writing to a log rather than directly to disk provides two major advantages: speed and efficiency. Because the log is append-only, writes are much faster, and multiple transactions can be grouped together and flushed to disk in a single operation.</p><p><strong>Physical and Logical journaling<br></strong>Journaling can be broadly classified into two types: physical and logical. <em>Physical journaling</em> operates at the block level, recording all changed metadata blocks such as inode bitmaps, block bitmaps, and directory entries — making it a relatively heavy operation. It is a block level journaling. A well-known example in Linux is Journaling Block Device version 2 (JBD2). Each JBD2 commit stores a minimum of 3 blocks (4KB) — descriptor, changed metadata block (atleast one) and commit marker which occurs 2 I/O writes — first two can be combined in one write and third in the next write. <br>In contrast, <em>logical journaling</em> is lighter, storing only the operations to be performed and deferring their processing (CPU work) until the log is flushed. In contrast to physical journaling, this supports file level journaling. The XFS filesystem uses this approach.</p><p>What is <strong>fsync</strong>? <br>It is a system call that forces in-memory data to be written to disk. Being a <strong>blocking call</strong>, it does not return until the storage device confirms that the data has been safely persisted to stable storage.</p><p><strong>Ext4 and NFS</strong><br><em>Ext4</em> is a widely used Linux filesystem that supports journaling to ensure consistency. Many cloud providers like AWS, GCP and Azure use ext4 as their backend.</p><p><em>Network File System</em> (NFS) is a protocol for distributed file sharing. It supports both asynchronous and synchronous modes. In async mode, the NFS client can open a file, write data, and close it, with the data being flushed to stable storage via an <em>fsync</em> call only when the file is closed. In contrast, sync mode issues an <em>fsync</em> after every metadata update. While this ensures stronger consistency, it comes at the cost of reduced performance.</p><p><strong>Slow and fast commits</strong><br>A <em>slow commit </em>takes a<strong> long time </strong>to complete because it writes <strong>large amounts of metadata or data to disk</strong> whereas a <em>fast commit</em> is <strong>quick</strong> and <strong>frequent</strong> because it consists of small data changes.</p><p>Now that we know the prerequisites for this paper, let’s understand <strong>why this paper is important</strong>.</p><p>While storing data in ext4, NFS issues fsync calls for every metadata write and JBD2 being the default physical journaling mechanism in ext4, it <strong>consumes 76% of the disk’s write bandwidth </strong>leading to high journal byte and I/O overhead. JBD2 was designed for a system with minimum fsync calls. <em>FastCommit claims to</em><strong><em> minimize fsync latency</em></strong><em> by </em><strong><em>2.8x</em></strong><em> and improve the overall </em><strong><em>throughput</em></strong><em> upto </em><strong><em>120%</em></strong><em>.</em></p><p>Idea: FastCommits aims to combine physical and logical journaling for slow and fast commits respectively to provide a hybrid approach. The logical journaling would only be performed between successive slow commits (occurs every 4 seconds). FastCommit simply logs the logical offsets in the inodes that were affected by this write compared to JBD2 which records all the metadata blocks that were changed by this transaction.<br>Eg — In case of a new write, it would log something like <em>inode i1 — offset 42 allocated</em>.</p><p><strong>1.Compact Logging<br></strong>A FastCommit commit is divided into multiple FCTags which are designed to be idempotent. These FCTags make up a FCLog and one or more FCLogs make up a FastCommit. FCLog always start with a head tag consisting of previous slow commit id and ends with a tail tag which contains the checksum of the FCLog (similar to the commit marker in JBD2)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/1*C9AMGhE5I3_mHh0tUnH_5A.png" /><figcaption>FCTags, part of FCLog in FCArea | Credits: FastCommit Usenix paper</figcaption></figure><p>1 FastCommit usually takes only 1 4KB blocks compared to JBD2 which takes 3 blocks i.e. 12KB. FastCommit is a set of <strong>8 tags</strong> whereas XFS has around <strong>40 tags</strong> which is the exact reason why we <em>cannot simply move to logical journaling but have to adopt a hybrid approach</em>.***</p><p><strong>2. Selective Flushing<br></strong>Flushing is unavoidable during data writes and when journal commit blocks are persisted. In JBD2, a flush is issued after writing the data blocks, updated metadata, and their corresponding descriptor to the journal area to ensure the data reaches stable storage. The commit marker is written using Force Unit Access (FUA), allowing JBD2 to ensure durability without an extra flush, saving one expensive disk operation. In contrast, Fast Commit (FC) logs are small enough to fit within a single 4 KB block, so the write can be considered complete without performing an expensive cache flush — provided no data blocks are being written.</p><p><strong>3. Inline Journaling<br></strong>A JBD2 commit involves two context switches:<br>1. The user thread writes data to the cache and calls fsync.<br>2. This wakes up the journal thread (first context switch, higher priority) to perform the commit.<br>Once the commit is complete, the user thread is woken up again (second context switch, lower priority). Because the journal thread has higher priority, the delay after the first switch is minimal, as it can preempt other low-priority threads. The second switch, however, introduces more delay because the user thread has lower priority.<br>In contrast, FastCommit performs the entire operation within the user thread using inline journaling, eliminating context switches. To ensure timely completion, the user thread’s priority is temporarily raised to match that of the journal thread during the commit. Once the write finishes, its priority returns to normal. This approach avoids context-switch overhead and reduces delays.</p><blockquote>***Quick note: When full block copies might still be needed?<br>1. Some updates are not easily representable as a small operation, e.g.:<br>2. Bulk updates to very large metadata blocks that cannot be expressed as a simple logical descriptor.<br>3. Complex journaling operations that touch multiple unrelated blocks in a single step and can’t easily reconstruct deterministically from a logical update.<br>In such cases, JBD2-style <strong>full-block journaling</strong> may still be used, even within FastCommit.</blockquote><p><strong>Crash Recovery</strong><br>There are 2 important considerations while performing Crash Recovery for FastCommits -</p><ol><li>Replay Order Relative to Slow Commits:<br>As explained in Compact Logging, the head FCTag stores the commit ID of the last slow commit (JBD2). All FastCommits should be replayed only after this slow commit has completed successfully. Any FCTags that do not contain this commit ID are discarded.</li><li>Replay Idempotency:<br>FCTags store the results of filesystem operations, such as the reference counts of the inodes involved. This ensures idempotency: if a crash occurs during recovery and there is a mismatch in reference counts, the FastCommit operation is restarted from the beginning, maintaining correctness.</li></ol><p>FastCommit elegantly blends physical and logical journaling to achieve the best of both worlds — reducing fsync latency and improving throughput without compromising consistency.</p><p><a href="https://www.usenix.org/conference/atc24/presentation/shirwadkar">Paper Link</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be9aff55180b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Episode1: Paper Notes for WiscKey]]></title>
            <link>https://medium.com/@psparkar_b16/episode1-paper-notes-for-wisckey-962c7ad9814d?source=rss-2031054fd437------2</link>
            <guid isPermaLink="false">https://medium.com/p/962c7ad9814d</guid>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[data-storage]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[storage]]></category>
            <dc:creator><![CDATA[Prachiti Parkar]]></dc:creator>
            <pubDate>Mon, 08 Sep 2025 04:35:05 GMT</pubDate>
            <atom:updated>2025-09-08T22:43:58.659Z</atom:updated>
            <content:encoded><![CDATA[<p>I stumbled upon this website recently which shared bite-sized notes on research papers. Those quick summaries were super helpful since research papers aren’t always the easiest to get through! I loved the idea, so I decided to try something similar here. For me, it’s having a handy way to revisit the papers I’ve gone through and share what I read.</p><p>This series will contain episodes structured into two parts — the first page will break down the key jargon and concepts needed to follow the paper and the next two pages would cover the potential takeaways of this paper.</p><p>Today we are talking about <strong><em>WiscKey</em></strong><em>: Separating Keys from Values in SSD-conscious storage.</em></p><p><strong>Why this paper?</strong> <em><br></em>This paper claims that they are better than LevelDB and RocksDB, two of the most accepted LSM tree datastructures out there for random writes and to some extent even lookups.</p><h4><strong>Concepts -</strong></h4><p>What is a <strong>LSM tree</strong>?<br>Log-Structured Merge (LSM) trees are key-value data structures designed for write-heavy workloads, especially on disk or flash storage.<br>They handle writes efficiently by first storing data in a Memtable (an in-memory tree or buffer), avoiding the cost of writing directly to disk.<br>When the Memtable fills up completely, its contents are flushed to disk into SSTables (Sorted String Tables).<br><em>SSTables</em> are append-only, with no overwrites, making them fast and efficient. They are organized into levels, with deeper levels holding more data. Searches begin at level 0 and continue to lower levels until the key is found.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g_-TOs0D4vvOeMJ3yfuCJg.png" /><figcaption>Read &amp; Write Path in a LSM Tree | Credits — Srishti Chaurasia</figcaption></figure><p><strong>Write amplification<br></strong>To put this in the easiest way, it is the number of extra writes done to write the data to the actual storage (including in-memory writes) compared to the number of writes the user has asked for.</p><p><em>WA= Bytes written to the storage device / Bytes requested by the user</em></p><p>Now that we know about most of the jargon required, let’s get to the main part.<br>WiscKey focusses on 4 main ideas —</p><p>1. <strong>Separate keys from values</strong><br>The main cost in LSM trees comes from compaction. Since data moves from Memtables to SSTables, these tables must be repeatedly sorted, which increases write amplification. WiscKey addresses this by storing only the keys in the LSM tree, along with pointers to the values, while the actual values are kept in vLog (value-log files). This greatly reduces database size and, in turn, write amplification.<br>At first, it may seem that WiscKey slows down lookups due to the extra I/O needed to fetch values. But with fewer levels to search for keys, lookup performance improves overall. In addition, a larger portion of the LSM tree can be cached, further boosting performance.</p><p>2. <strong>Parallel random reads</strong><br>A key challenge for WiscKey was supporting range queries, which are crucial in modern key-value stores. In LevelDB, keys and values are stored together, so range queries can simply scan SSTables using Next() and Prev(). But in WiscKey, since values are stored separately, range queries would require random reads to fetch them — adding extra cost compared to other LSM trees.</p><p>To address this, WiscKey uses the parallel I/O capability of SSDs along with queues to maintain similar performance. Once a sequence of keys is read from the LSM, their value addresses are queued, allowing multiple threads to fetch values from the vLog in parallel. This prefetching lets keys be scanned sequentially while values are retrieved concurrently in the background.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*zfkSgh3PFKajICeuVIljbQ.png" /><figcaption>Parallel range query in WiscKey</figcaption></figure><p>3. <strong>Unique Garbage collection &amp; Crash consistency<br></strong>WiscKey only discards invalid keys during LSM tree compaction and hence needs a special mechanism to handle GC for vLogs. To make things easier, they also store the key with the value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/710/1*YpkduDP6rk_a0CRn6wxsNg.png" /><figcaption>Garbage Collection is WiscKey | credits: tech-lessons.in</figcaption></figure><p>The region between the head and tail contains valid values. Garbage collection starts at the tail; if the value is valid (its key is present in the LSM), it is copied to the head, the head offset is updated, and the old space at the tail is freed as the tail moves forward. To ensure crash safety, the updated tail position is recorded in the LSM tree.</p><p>Crash consistency is simple. If a crash leaves a value in the vLog without its key in the LSM, garbage collection will remove it, as in a standard LSM. If the key exists, the value’s address is checked: if it lies outside the head–tail range, the key is removed from the LSM and the value will later be reclaimed by GC.</p><p>4. <strong>Performant removal of LSM tree log<br></strong>The head’s offset is stored in the LSM tree. This ensures that if a crash occurs during multiple small inserts, recovery can begin from the persisted head in the vLog to check and restore missing keys in the LSM. As a result, there’s no need for a separate WAL, eliminating the LSM log step.</p><p>Overall, WiscKey is a strong alternative to LevelDB and RocksDB, especially for write-intensive workloads on SSDs. However, the added complexity of garbage collection and sequential writes can make simpler designs more appealing. In practice, the trade-off comes down to whether the performance gains outweigh the operational overhead.</p><p>Be tuned for more such summarized research papers :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=962c7ad9814d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pointers and References in C++]]></title>
            <link>https://medium.com/@psparkar_b16/pointers-and-references-ebac61e8deff?source=rss-2031054fd437------2</link>
            <guid isPermaLink="false">https://medium.com/p/ebac61e8deff</guid>
            <dc:creator><![CDATA[Prachiti Parkar]]></dc:creator>
            <pubDate>Mon, 15 Apr 2024 02:42:33 GMT</pubDate>
            <atom:updated>2024-04-24T02:03:32.824Z</atom:updated>
            <content:encoded><![CDATA[<p>People often say pointers and references are the same thing inherently. But are they? Let’s debunk this.</p><p>For ease, I have split this topic into four parts.</p><ol><li><em>Basic Definitions</em></li><li><em>Differences</em></li><li><em>Use of Pointers vs. References</em></li><li><em>History of References (You need to understand basic definitions before you can understand this)</em></li></ol><p>Note: If you’re studying for interviews, I would suggest reading the first 3 points and calling it a topic. C++ is huge, and you don’t want to spend your day just reading about pointers because, trust me, it’s a rabbit hole :)</p><h3>Basic Definitions</h3><p><strong>Pointers:</strong></p><figure><img alt="Credits: C++ Pointers Concept with Example — Simple Snippets" src="https://cdn-images-1.medium.com/max/561/1*CzHV16Bl1to5QlK8_gnEgg.jpeg" /><figcaption><a href="https://simplesnippets.tech/cpp-pointers-concept-with-example/">C++ Pointers Concept with Example — Simple Snippets</a></figcaption></figure><p>A pointer is a variable that points to another variable, i.e. it holds the memory address of another variable. It is a<strong> “true”</strong> value type. The value of a pointer is an actual, real memory location. You can observe this directly; if you print a pointer without dereferencing it (in simple words, using a variable without the * operator), the value printed is the memory address value the pointer holds. In simple words, it’s easier to give someone an address to your home than to give a copy of your home to everyone; this is the best explanation of pointers I have heard.</p><p><strong>References:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/1*U3iXIPFM3FKkxYV3SbO_lg.png" /><figcaption><a href="https://www.scaler.com/topics/cpp-return-reference/">Credits: C++ Return Reference</a></figcaption></figure><p>A reference variable is an alias, another name for an already existing variable.<br>Example 1:</p><pre>int a =10;<br>int &amp;b = a;<br>cout&lt;&lt;&quot;Value of b is &quot;&lt;&lt;b&lt;&lt;endl; //10<br>cout&lt;&lt;&quot;Address of a is &quot;&lt;&lt;&amp;a&lt;&lt;endl; <br>cout&lt;&lt;&quot;Address of b is &quot;&lt;&lt;&amp;b&lt;&lt;endl; // i.e a == b and &amp;a == &amp;b</pre><p>Example 2: sizeof(&amp;T), you will get the same answer as sizeof(T)</p><h3>Differences:</h3><p><strong><em>Initialization </em></strong><br>Pointers can be declared, then initialized <br>int *p; <br>p = &amp;a;<br>References need to be declared and initialized together <br>int &amp;p = a;</p><p><strong><em>NULL</em></strong><br>Pointers can be null, references cannot be.<br>References must be “bound” to an instance at initialization, they cannot have their separate existence.</p><p><strong><em>Reassignment</em></strong><br>The assignment of references cannot be changed, but pointers can be reassigned.</p><pre>// Reassignment of references isn&#39;t possible<br>// Let&#39;s continue the above example<br>int a =10;<br>int &amp;b = a;<br>int c = 20;<br>&amp;b = c; //Compiler Error<br>cout&lt;&lt;&quot;Value of b is &quot;&lt;&lt;b&lt;&lt;endl; </pre><p>Output:<br>./Solution.cpp:10:8: error: lvalue required as left operand of assignment<br> &amp;b = c;<br> ^</p><pre>int a =10;<br>int &amp;b = a;<br>int c = 20;<br>b = c; <br>cout&lt;&lt;&quot;Value of b is &quot;&lt;&lt;b&lt;&lt;endl; //20</pre><p>This doesn’t result in an error because we have not done a reassignment of reference here, b still refers to a but now the value of a is c i.e., 20.</p><p><strong><em>Independence</em></strong><br>Pointers can exist independently of having an object to point to, but references cannot.</p><p><strong><em>Memory management</em></strong><br>Pointers take up memory on the stack/heap i.e., have their own memory address and size; references share the same memory address as the original variable and take up no space on the stack. Since a reference isn’t a “true” value type, but instead defined as an alias to the bound instance, the compiler is free to implement references however it wants, as long as it <em>maintains the semantics</em>. This means a compiler is free to <em>optimize out a reference completely</em>.</p><p><strong><em>Indirection</em></strong><br>A pointer to pointer called a double pointer is valid. Reference only offers one level of indirection.</p><p><strong><em>Arithmetics</em></strong><br>Arithmetic operators can be applied to pointers, not references. These operations are addition and subtraction.</p><h3>Use of Pointers vs. References</h3><h4>When should you use pointers?</h4><ul><li>When the value that the pointer points to can be a NULL pointer. For example, this can happen when a function parameter is optional, we can initialize it as a NULL pointer. Moreover, you should always use a pointer in the case of data structures like linked lists, graphs, etc. since they can be NULL.</li><li>Dynamic Memory Allocation<br>It is defined as the process of allocating (using a new operator) or deallocating (using a delete operator) memory.<br>1. Unknown array size: In this case, it is better to use pointers since the pointer will only point to the start of the array, so we only need to know the beginning of the array; traversing the array can be handled by pointer arithmetics.</li></ul><h4>When should you use references?</h4><ul><li>Modify the local variable of the caller function<br>In this case, you can easily use references and change the value of the variable instead of having to deal with pointers.</li><li>Runtime polymorphism<br>When you want to pass derived or base class objects as arguments to a function, you can use references in the function parameters.</li><li>Space constraints<br>Though pointers are more space efficient than passing by value, they do occupy a fixed amount of memory space. If you want to avoid creating a copy of the desired variable and just create an alias, you can just use a reference and save space since it doesn’t take up any additional memory.</li><li>Copy constructor<br>While using Copy constructor, you can only use references because the use of pointers in this case can cause a dangling pointer issue if one of the objects is deleted or changed.</li></ul><p>Overall, I prefer using references instead of pointers. It is said that you should use references when you can and pointers when you must.</p><h3>History of References:</h3><p>Let’s start with some common bugs C had.</p><pre>int cool_value = 10;<br>int* cool_ptr;<br>cool_ptr = cool_value; //compiler error<br>// Did you mean to type *cool_ptr = cool_value?</pre><pre>cool_value = cool_ptr //compiler error <br>// Did you mean to type cool_value = *some_int_ptr?</pre><p>This is a common mistake and was the cause of many bugs in C. Bjarne wanted to avoid this and create an easy way because C++ is just a code generator for C. Hence, he created references (pointers’ alias without the “true” value) that didn’t need these wildcard operators like * or -&gt; and they looked just like normal variables.</p><p>So, to answer the question, I wouldn’t use pointers and references interchangeably if I wanted to be technically correct. If someone says this, you should think in terms of the generated machine assembly for indirect referencing, and how the generated assembly might store the addresses used for it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ebac61e8deff" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>