<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Manav Verma</title>
    <description>The latest articles on Forem by Manav Verma (@manaver).</description>
    <link>https://forem.com/manaver</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F890976%2F69f5bd6e-f568-4815-981b-697e0fd5fcbf.jpg</url>
      <title>Forem: Manav Verma</title>
      <link>https://forem.com/manaver</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/manaver"/>
    <language>en</language>
    <item>
      <title>🚨 Critical Next.js Vulnerability: Server Hijacked by Crypto Miner</title>
      <dc:creator>Manav Verma</dc:creator>
      <pubDate>Mon, 08 Dec 2025 03:44:29 +0000</pubDate>
      <link>https://forem.com/manaver/alert-my-nextjs-server-was-hijacked-by-a-crypto-miner-and-yours-might-be-too-426l</link>
      <guid>https://forem.com/manaver/alert-my-nextjs-server-was-hijacked-by-a-crypto-miner-and-yours-might-be-too-426l</guid>
      <description>&lt;p&gt;🚨 Critical Next.js Vulnerability: Server Hijacked by Crypto Miner&lt;/p&gt;

&lt;p&gt;If you are running Next.js (especially App Router), stop what you are doing and check your servers. I just spent the last 24 hours fighting a nightmare scenario where 2-3 of my production apps were suddenly compromised.&lt;/p&gt;

&lt;p&gt;Here is exactly what happened, how I found it, and how you can fix it.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Symptoms: "Suddenly, Silence"
&lt;/h3&gt;

&lt;p&gt;Everything was running smoothly until my server monitoring screamed.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;CPU Spikes:&lt;/strong&gt; Usage hit 100% and stayed there.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Server Shutdown:&lt;/strong&gt; The load was so high the VM eventually crashed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Filesystem Changes:&lt;/strong&gt; I noticed immediate changes in my git staging area—files I didn't touch were modified.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The Analysis: What the Hacker Did
&lt;/h3&gt;

&lt;p&gt;The attacker used a Remote Code Execution (RCE) vulnerability to gain entry and immediately set up shop to mine Monero (XMR).&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Code Level Compromise
&lt;/h4&gt;

&lt;p&gt;They didn't just run a script; they embedded themselves into my source code to ensure persistence.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Modified Configs:&lt;/strong&gt; Malicious lines were injected into &lt;code&gt;next.config.js&lt;/code&gt;, &lt;code&gt;tailwind.config.js&lt;/code&gt;, and &lt;code&gt;postcss.config.js&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Manifest Injection:&lt;/strong&gt; A custom manifest file was added.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Git Staged Changes:&lt;/strong&gt; I caught them red-handed via &lt;code&gt;git status&lt;/code&gt;—&lt;code&gt;yarn.lock&lt;/code&gt; and &lt;code&gt;package.json&lt;/code&gt; were modified to pull malicious dependencies.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5m1m72umsxlcxrefak4r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5m1m72umsxlcxrefak4r.png" alt=" " width="796" height="502"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  2. Machine Level Compromise
&lt;/h4&gt;

&lt;p&gt;This was the scary part. They escalated out of the Node.js process:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;System Services:&lt;/strong&gt; They created systemd services with random hexadecimal names (e.g., &lt;code&gt;a1b2c3d4.service&lt;/code&gt;) to restart the miner if I killed it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Shell Poisoning:&lt;/strong&gt; They added lines to my &lt;code&gt;.bashrc&lt;/code&gt; and &lt;code&gt;.profile&lt;/code&gt; so the miner would start whenever I logged in.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  3. The Payload (&lt;code&gt;xmrig&lt;/code&gt;)
&lt;/h4&gt;

&lt;p&gt;They installed &lt;code&gt;xmrig&lt;/code&gt;, a high-performance Monero miner. I found a &lt;code&gt;config.json&lt;/code&gt; file dropped in the miner's directory configured to use &lt;code&gt;max-threads-hint: 100&lt;/code&gt; and &lt;code&gt;huge-pages&lt;/code&gt;, which explains why the server was choking.&lt;/p&gt;




&lt;h3&gt;
  
  
  How I Cleaned It Up (Remediation Guide)
&lt;/h3&gt;

&lt;p&gt;If you are infected, you need to act fast. Here is the cleanup process I used.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Stop the Bleeding&lt;/strong&gt;&lt;br&gt;
Immediately kill the miner processes. Note: The process might be named &lt;code&gt;xmrig&lt;/code&gt;, but attackers often rename it to look like a system process.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Force kill all processes matching "xmrig"&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;pkill &lt;span class="nt"&gt;-9&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; xmrig
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Tip: Check &lt;code&gt;top&lt;/code&gt; or &lt;code&gt;htop&lt;/code&gt; for any other processes taking 80-90% CPU and kill them.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Remove Persistence (Systemd Services)&lt;/strong&gt;&lt;br&gt;
The attackers hid services with random hex names.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# List all running services and look for random hex strings&lt;/span&gt;
systemctl list-units &lt;span class="nt"&gt;--type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;service &lt;span class="nt"&gt;--state&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;running

&lt;span class="c"&gt;# Stop and disable suspicious services&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl stop &lt;span class="o"&gt;[&lt;/span&gt;service_name]
&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl disable &lt;span class="o"&gt;[&lt;/span&gt;service_name]
&lt;span class="nb"&gt;sudo rm&lt;/span&gt; /etc/systemd/system/[service_name]
&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl daemon-reload
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Clean System Shells&lt;/strong&gt;&lt;br&gt;
Check your shell profiles (&lt;code&gt;~/.bashrc&lt;/code&gt;, &lt;code&gt;~/.profile&lt;/code&gt;). Remove any lines that look like &lt;code&gt;curl&lt;/code&gt; commands fetching scripts or exports you didn't add.&lt;/p&gt;
&lt;h4&gt;
  
  
  🏠 &lt;strong&gt;VITAL: Check for HOME Directory Hijacking&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;A sophisticated attacker may hijack your environment variables to break tools like NVM/Conda or redirect configuration files to a temporary directory (&lt;code&gt;/tmp&lt;/code&gt;), where they can hide or run malware.&lt;/p&gt;

&lt;p&gt;To see if this has happened to your &lt;code&gt;$HOME&lt;/code&gt; variable, run these commands:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Check the currently set variable:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$HOME&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;If this outputs &lt;code&gt;/tmp&lt;/code&gt; or any path other than &lt;code&gt;/home/yourusername&lt;/code&gt;, your environment is poisoned.&lt;/p&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Find the malicious override:&lt;/strong&gt;&lt;br&gt;
You need to search the system-wide configuration files (where the attacker placed the reset command) for the incorrect path. Replace &lt;code&gt;/tmp&lt;/code&gt; with the incorrect path found in step 1 if necessary:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo grep&lt;/span&gt; &lt;span class="nt"&gt;-R&lt;/span&gt; &lt;span class="s1"&gt;'HOME=/tmp'&lt;/span&gt; /etc
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;The output will point you to the exact file (e.g., &lt;code&gt;/etc/profile.d/env.sh&lt;/code&gt;). &lt;strong&gt;Edit that file (using &lt;code&gt;sudo&lt;/code&gt;) and remove the line&lt;/strong&gt; to restore your system's default behavior.&lt;/p&gt;


&lt;/li&gt;

&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;4. Clean the Codebase &amp;amp; Verify Configs&lt;/strong&gt;&lt;br&gt;
Resetting git is a good start, but &lt;strong&gt;you must manually verify the content of your config files&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Reset local changes&lt;/span&gt;
git reset &lt;span class="nt"&gt;--hard&lt;/span&gt; HEAD
git clean &lt;span class="nt"&gt;-fd&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;⚠️ Vital Step:&lt;/strong&gt; Open your &lt;code&gt;next.config.js&lt;/code&gt;, &lt;code&gt;tailwind.config.js&lt;/code&gt;, and system files. Read them line-by-line. Attackers are getting better at obfuscating code.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Pro Tip:&lt;/strong&gt; If you see a block of code in your config that looks suspicious or complex, &lt;strong&gt;copy and paste it into an AI tool (like ChatGPT or Gemini)&lt;/strong&gt; and ask: &lt;em&gt;"Is this code malicious? What does it do?"&lt;/em&gt; Don't take chances.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;5. Rotate Secrets&lt;/strong&gt;&lt;br&gt;
Since they had RCE, assume they stole your &lt;code&gt;.env&lt;/code&gt; file. Revoke and generate new database credentials and API keys immediately.&lt;/p&gt;


&lt;h3&gt;
  
  
  Final Step: Patch Immediately!
&lt;/h3&gt;

&lt;p&gt;Cleaning the miner doesn't close the door. You &lt;strong&gt;must&lt;/strong&gt; upgrade Next.js to the latest patched version to prevent them from walking right back in.&lt;/p&gt;

&lt;p&gt;Please refer to the official Next.js security blog for the exact version numbers you need to target:&lt;br&gt;
👉 &lt;strong&gt;&lt;a href="https://nextjs.org/blog/CVE-2025-66478" rel="noopener noreferrer"&gt;Next.js Security Advisory: CVE-2025-66478&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Update your dependencies accordingly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;next@latest react@latest react-dom@latest
&lt;span class="c"&gt;# or&lt;/span&gt;
yarn add next@latest react@latest react-dom@latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Deep Dive Analysis
&lt;/h3&gt;

&lt;p&gt;For a detailed technical breakdown of how this "React2Shell" vulnerability works and how the attackers exploit it, read this report:&lt;br&gt;
👉 &lt;strong&gt;&lt;a href="https://www.wiz.io/blog/critical-vulnerability-in-react-cve-2025-55182" rel="noopener noreferrer"&gt;Wiz.io: Critical Vulnerability in React (CVE-2025-55182)&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Stay safe and check your logs!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; FOR SAFETY I PREFER RESET ALL OF YOUR CREDENTIALS AND MIGRATE TO NEW INSTANCE OR SERVER&lt;/p&gt;

&lt;p&gt;Let me know in the comments what you think about this solution and how you are handling these security challenges in your own projects.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>nextjs</category>
      <category>cryptocurrency</category>
      <category>hijacked</category>
    </item>
    <item>
      <title>Exploring the Foundational Hashing Concept in C++ and Beyond</title>
      <dc:creator>Manav Verma</dc:creator>
      <pubDate>Tue, 13 Feb 2024 06:47:40 +0000</pubDate>
      <link>https://forem.com/manaver/exploring-hashmaps-and-hash-tables-in-c-ono</link>
      <guid>https://forem.com/manaver/exploring-hashmaps-and-hash-tables-in-c-ono</guid>
      <description>&lt;h1&gt;
  
  
  Hashmaps
&lt;/h1&gt;

&lt;p&gt;In C++, hashmaps plays a crucial role in efficient data storage and retrieval. To understand how hashmaps work, let's delve into the concepts of hashing and &lt;strong&gt;Hash Tables&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hashing
&lt;/h2&gt;

&lt;p&gt;First, let's start with the concept of hashing, it is a process of converting data (text, numbers, files, or anything) into a fixed-length string of letters and numbers known as a &lt;strong&gt;Hash Code&lt;/strong&gt;. This transformation is achieved through a specialized algorithm called a &lt;strong&gt;Hash Function&lt;/strong&gt;.&lt;br&gt;
&lt;a href="https://www.canva.com/design/DAE2RhkfOZI/KH9yMmREbam2ARKJ5-Tg4Q/edit?utm_content=DAE2RhkfOZI&amp;amp;utm_campaign=designshare&amp;amp;utm_medium=link2&amp;amp;utm_source=sharebutton"&gt;Hashing Techniques in PPT format&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  How hashing works?
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Input data is the key
&lt;/h4&gt;

&lt;p&gt;The input data to be hashed is also referred to as the key. Keys can be in various formats, such as a string of text, a list of numbers, an image, or even an application file.&lt;/p&gt;

&lt;h4&gt;
  
  
  The hash function
&lt;/h4&gt;

&lt;p&gt;The core component of any hashing process is the hash function. This function takes the key and converts it into a fixed-length string of characters.&lt;/p&gt;

&lt;h3&gt;
  
  
  Where hashing works?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;In large database structures, searching through all index values across different levels to reach the desired data block can be time-consuming. Hashing addresses this issue by allowing faster searches using shorter hashed keys instead of the original values.&lt;/li&gt;
&lt;li&gt;Hashing is employed to index and retrieve items in a database, providing a quicker way to search for specific items using their hashed keys.&lt;/li&gt;
&lt;li&gt;It proves to be an efficient method for determining the direct location of a data record on a disk without relying on complex index structures.&lt;/li&gt;
&lt;li&gt;Hashing is also beneficial for implementing dictionaries.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Hash Tables
&lt;/h2&gt;

&lt;p&gt;Hash tables are like organized boxes where we can quickly put things and find them later. They are handy for storing and finding information quickly. Imagine a bunch of labeled boxes (buckets) where we keep our stuff (data elements). We use a special method called hashing to decide which box to put each thing in based on its characteristics. This helps us easily locate and retrieve our items when needed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F34j8tk71q80jfld5wi5o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F34j8tk71q80jfld5wi5o.png" alt="Image description" width="800" height="504"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Structure of Hash Tables
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Array&lt;/strong&gt;: The backbone of a hash table is an array where data elements are stored. Each element in the array is often referred to as a bucket or slot.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hash Function&lt;/strong&gt;: Hash tables use a hash function to compute an index or hash code for each data element. This index determines the position where the element will be stored in the array.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Collision Handling&lt;/strong&gt;: Since multiple data elements may hash to the same index, collisions can occur. Hash tables employ various collision resolution techniques to handle this issue, such as chaining or open addressing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Key-Value Pairs&lt;/strong&gt;: Data elements stored in a hash table are typically in key-value pairs. The key is used to compute the hash code, and the value is the associated data.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Complexity Analysis
&lt;/h3&gt;

&lt;p&gt;The complexity of a hash table depends on the hash function picked. The more collisions it generates, the more the complexity tends toward Θ(n). Hash tables have a Θ(1) complexity in best and average-case scenarios but fall to Θ(n) in their worst-case scenario.&lt;/p&gt;

&lt;h3&gt;
  
  
  Hashing Concept in C++
&lt;/h3&gt;

&lt;p&gt;We can say that Hashing is &lt;em&gt;pre-storing and then fetch&lt;/em&gt; when needed. let's check some hashing methods:&lt;/p&gt;

&lt;h4&gt;
  
  
  Number Hashing
&lt;/h4&gt;

&lt;p&gt;Consider an array: &lt;/p&gt;

&lt;p&gt;Given Number lies in the range &amp;lt;=0 and &amp;gt;=8 &lt;br&gt;
&lt;code&gt;arr[] = {2, 3, 3, 1, 2, 3, 4, 6, 7, 1}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;First, we have to do prefetching for that we will make a has array as shown in the diagram&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx8ohmaai8bcfwfhwebgf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx8ohmaai8bcfwfhwebgf.png" alt="Image description" width="800" height="179"&gt;&lt;/a&gt;&lt;br&gt;
&lt;code&gt;hash[9] = {0}&lt;/code&gt;&lt;br&gt;
new hash array initialized with 0&lt;br&gt;
Now We have to prefetch the values in the has array &lt;br&gt;
according to the number of times, the value appears like this:&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F51g3sajg5ho4wd4decrh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F51g3sajg5ho4wd4decrh.png" alt="Image description" width="800" height="179"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The provided information is clear and provides insights into the occurrences of values in the given array. However, I suggest a slight modification for improved clarity and organization:&lt;/p&gt;

&lt;p&gt;From the diagram above, we can easily extract several details about the given array:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1 appears 2 times&lt;/li&gt;
&lt;li&gt;2 appears 2 times&lt;/li&gt;
&lt;li&gt;3 appears 3 times&lt;/li&gt;
&lt;li&gt;4 appears 1 time&lt;/li&gt;
&lt;li&gt;6 appears 1 time&lt;/li&gt;
&lt;li&gt;7 appears 1 time
For all other values, the occurrences are 0 times. This can be expressed as hash[1] = 2, hash[2] = 2, hash[3] = 3, hash[4] = 0, and so on.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Additionally, it's noteworthy to consider the maximum array size in C++ under different scenarios:&lt;/p&gt;

&lt;p&gt;Case 1: (Declared Inside Main Function)&lt;br&gt;
The maximum size for an array declared inside the main function is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;arr[10^6]&lt;/code&gt; (for an integer array)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;arr[10^7]&lt;/code&gt; (for a boolean array)
Case 2: (Declared Globally)&lt;/li&gt;
&lt;li&gt;If declared globally, the maximum size can extend up to &lt;code&gt;arr[10^7]&lt;/code&gt;. In this case, every element in the array is initialized to 0 by default if not explicitly assigned.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Try to solve this problem with this approach and you can see how easily hashing solves our problem: &lt;a href="https://takeuforward.org/data-structure/count-frequency-of-each-element-in-the-array/"&gt;Count Frequency&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Character Hashing
&lt;/h4&gt;

&lt;p&gt;In character hashing, a process similar to number hashing, characters are mapped into an array. &lt;br&gt;
The approach to achieving this in programming involves utilizing ASCII values.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.w3schools.com/charsets/ref_html_ascii.asp"&gt;ASCII aka American Standard Code for Information Interchange&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Consider an example:&lt;br&gt;
&lt;code&gt;int x = 'a'; //Automatically typecast 'a' to 97 which is ASCII code&lt;/code&gt;&lt;br&gt;
i.e. similar to &lt;code&gt;int x = 97;&lt;/code&gt;&lt;br&gt;
therefore, 'b' is 98, 'c' is 99, ..., y is 121 and z is 122&lt;/p&gt;

&lt;p&gt;Let's get back to how can we hash it,&lt;br&gt;
A quick question for you, if you what is the value of x here &lt;br&gt;
      &lt;code&gt;x = 'a' - 'a'&lt;/code&gt;&lt;br&gt;
Yes! you guessed it right, x = 0 here&lt;br&gt;
if we do x = 'b' - 'a', then x = 1&lt;br&gt;
.... x = 'z' - 'a' gives 25 i.e. x = 25&lt;br&gt;
here we get our range i.e. 0 to 25 (and there are 26 letters in English alphabets)&lt;br&gt;
Consider an example&lt;br&gt;
s = "abcdbeadf"&lt;/p&gt;

&lt;p&gt;Similar to number hashing, we have to do prefetching for that we will make a has array &lt;br&gt;
as shown in diagram:&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmqnf6l6hktd9a86fnrye.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmqnf6l6hktd9a86fnrye.png" alt="Image description" width="800" height="179"&gt;&lt;/a&gt;&lt;br&gt;
&lt;code&gt;hash[26] = {0}&lt;/code&gt;&lt;br&gt;
new hash array initialized with 0&lt;br&gt;
Now We have to prefetch the values in the has array &lt;br&gt;
according to the number of times the value appears like this:&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd8u6gzf2i623rw4ul2lj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd8u6gzf2i623rw4ul2lj.png" alt="Image description" width="800" height="179"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This exploration of hashmaps and hash tables is just the tip of the iceberg. There's a vast sea of knowledge and applications waiting to be uncovered. Keep diving deeper, learning more, and discovering the multitude of possibilities that these powerful data structures bring to your programming toolkit. Happy coding! 🚀📚&lt;/p&gt;

</description>
    </item>
    <item>
      <title>C++ Arrays: A Guide to Understanding, Storing, and Expanding with Vectors</title>
      <dc:creator>Manav Verma</dc:creator>
      <pubDate>Sun, 11 Feb 2024 06:38:12 +0000</pubDate>
      <link>https://forem.com/manaver/c-arrays-a-guide-to-understanding-storing-and-expanding-with-vectors-141e</link>
      <guid>https://forem.com/manaver/c-arrays-a-guide-to-understanding-storing-and-expanding-with-vectors-141e</guid>
      <description>&lt;p&gt;In C++, arrays provide a fundamental data structure for organizing and managing collections of values of the same type. This blog post delves into arrays, explores their capabilities, and guides you through effective usage patterns.&lt;/p&gt;

&lt;h3&gt;
  
  
  Understanding Arrays:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Concept:&lt;/strong&gt; Arrays store multiple elements of the same data type in consecutive memory locations. Each element, identified by its index (starting from 0), can be directly accessed and manipulated.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Declaration:&lt;/strong&gt; Declare an array using its data type, name, and size enclosed in square brackets:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;data_type array_name[size];&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;-&lt;strong&gt;Initialization:&lt;/strong&gt; Arrays can be initialized during declaration using curly braces ({}) to provide initial values, or assigned values later.&lt;/p&gt;

&lt;h3&gt;
  
  
  Storing Roll Numbers Effectively:
&lt;/h3&gt;

&lt;p&gt;While directly creating individual variables is viable for a few students, arrays become essential for efficient storage and management of larger groups.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvnt2mgx7ng82xmhqqfif.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvnt2mgx7ng82xmhqqfif.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Points:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;This snippet dynamically calculates the number of students using the sizeof operator.&lt;/li&gt;
&lt;li&gt;Arrays simplify data organization and retrieval, promoting code readability and maintainability.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Addressing Array Limitations:
&lt;/h3&gt;

&lt;p&gt;Arrays do have limitations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Fixed Size:&lt;/strong&gt; Predefined size can become inflexible if the number of elements changes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Memory Management:&lt;/strong&gt; Manual allocation and deallocation can be error-prone, requiring careful attention.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Introducing Vectors: A Dynamic Array Alternative
&lt;/h3&gt;

&lt;p&gt;C++'s Standard Template Library (STL) provides std::vector, a dynamic array that overcomes these limitations:&lt;/p&gt;

&lt;p&gt;Using std::vector:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fduf913t18fob827s8oc6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fduf913t18fob827s8oc6.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Dynamic Growth:&lt;/strong&gt; Add or remove elements at runtime using push_back() and pop_back().&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Automatic Memory Management:&lt;/strong&gt; No manual allocation/deallocation needed, reducing error risks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Iterators:&lt;/strong&gt; Simplified access and manipulation of elements using iterators.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Conclusion:
&lt;/h3&gt;

&lt;p&gt;Choose arrays when the size is known at compile time and memory management is straightforward. Opt for std::vector for scenarios with dynamic data requirements and flexibility concerns. By understanding their strengths and weaknesses, you can make informed decisions and leverage these data structures effectively in your C++ programs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Practice Questions:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://takeuforward.org/data-structure/find-the-largest-element-in-an-array/" rel="noopener noreferrer"&gt;Largest element in array&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://takeuforward.org/data-structure/find-second-smallest-and-second-largest-element-in-an-array/" rel="noopener noreferrer"&gt;2nd Largest and Smallest element in array&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://takeuforward.org/data-structure/check-if-an-array-is-sorted/" rel="noopener noreferrer"&gt;If Array Is Sorted&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://takeuforward.org/data-structure/remove-duplicates-in-place-from-sorted-array/" rel="noopener noreferrer"&gt;Remove Duplicates&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Demystifying Memory in Rust: Ownership, Borrowing, and the Memory Landscape:</title>
      <dc:creator>Manav Verma</dc:creator>
      <pubDate>Wed, 10 Jan 2024 09:24:25 +0000</pubDate>
      <link>https://forem.com/manaver/demystifying-memory-in-rust-ownership-borrowing-and-the-memory-landscape-1f4f</link>
      <guid>https://forem.com/manaver/demystifying-memory-in-rust-ownership-borrowing-and-the-memory-landscape-1f4f</guid>
      <description>&lt;p&gt;Memory management is very important for any program, but in Rust, it takes center stage. Unlike languages with automatic garbage collection, Rust grants you deep control over where and how data resides - a superpower fueled by the innovative concepts of ownership and borrowing.&lt;/p&gt;

&lt;p&gt;Have a look at some of the memory management techniques used by other programming languages.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PAS8JWgz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2xpqoirjddaapmd0oh3v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PAS8JWgz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2xpqoirjddaapmd0oh3v.png" alt="Image description" width="800" height="580"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before understanding the concept of ownership and borrowing, we need to know about stack and heap:&lt;/p&gt;

&lt;h3&gt;
  
  
  Stack:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OtK4UxH8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/481ucscycrrzt3q202bt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OtK4UxH8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/481ucscycrrzt3q202bt.png" alt="Image description" width="800" height="348"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The stack is a region of memory that grows and shrinks automatically as functions push and pop frames on it. It's used for static memory allocation, which includes local primitive variables and function pointers. The stack is managed by the CPU, which makes it faster to allocate and deallocate memory compared to the heap. However, the size of the stack is limited and determined at the start of each thread. It's important to note that you can't control the lifespan of memory on the stack; when a function exits, all of its stack memory is reclaimed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Heap:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fJpf0Kww--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9lnotu0dnboag2hju1nt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fJpf0Kww--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9lnotu0dnboag2hju1nt.png" alt="Image description" width="800" height="466"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The heap is a memory region for dynamic allocation, managed manually. It allows variables to have a global, flexible lifespan. Memory can be allocated at runtime, used until freed by the programmer or program's end. Manual management can lead to errors like memory leaks or dangling pointers. When data is added to the heap, the allocator finds a sufficient empty area, marks it as used, and returns a pointer to the location. This pointer can be stored in the stack for future reference. To retrieve data, follow the pointer to the heap location.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--X_grRAQb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ifkdwh3d4naybe2oya56.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--X_grRAQb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ifkdwh3d4naybe2oya56.png" alt="Image description" width="800" height="965"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this article, we're focusing on the String datatype in Rust, which is more complex than primitive datatypes such as i32 or f32. Unlike these fixed-size datatypes, a String's size isn't known at compile time, which means it can't be stored on the stack. Consequently, it isn't automatically cleaned up when its owning variable goes out of scope. Therefore, it's crucial to understand how Rust handles the cleanup process for Dynamically allocated variables.&lt;/p&gt;

&lt;p&gt;Now let's start with Ownership&lt;/p&gt;

&lt;h3&gt;
  
  
  Ownership:
&lt;/h3&gt;

&lt;p&gt;In Rust, Every piece of data in Rust has a clear owner responsible for its memory allocation and release. When the owner goes out of scope, the data and its memory are automatically reclaimed, preventing leaks and dangling pointers. Imagine each piece of data having a single, responsible caretaker.&lt;br&gt;
This eliminates manual memory management, as the ownership system handles memory deallocation automatically.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fn main(){
    let s = String::from("hello"); // s is the owner of the string "hello"
    let t = s; // ownership of the value of s is not transferred to t
    println!("{}", s); //gives an error because ownership of is transferred so s does not have any value
    println!("{}", t); // shows hello
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Rust, if we want to have multiple borrowers of a single value we have borrowers i.e. borrowing with rules&lt;/p&gt;

&lt;p&gt;Lifetimes: Lifetimes define how long references are valid. They ensure that borrowed references don't outlive the data they point to, preventing the dreaded "dangling references".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fn main(){
    loop {
        let x = 5; // x is only valid in this scope
    }
    println!("{}",x); // Unreachable Code
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  References:
&lt;/h3&gt;

&lt;p&gt;In Rust, references allow you to access the data of a variable without taking ownership. Here are some key points:&lt;/p&gt;

&lt;h3&gt;
  
  
  Immutable References:
&lt;/h3&gt;

&lt;p&gt;By default, references are immutable. This means you can read from a reference, but you can't modify the data it points to.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let s = String::from("hello");
let r = &amp;amp;s; // r is an immutable reference to s
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Mutable References:
&lt;/h3&gt;

&lt;p&gt;If you need to modify the data reference points to, you can create a mutable reference using &amp;amp;mut. However, you can only have one mutable reference to a particular piece of data in a particular scope.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fn main(){
    let mut s = String::from("hello");
    let r = &amp;amp;mut s; // r is a mutable reference to s
    *r = String::from("world"); // This changes the value of s
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Dangling References:
&lt;/h3&gt;

&lt;p&gt;Rust ensures references are always valid. You can't create a dangling reference (a reference to data that no longer exists).&lt;/p&gt;

&lt;h3&gt;
  
  
  Borrowing:
&lt;/h3&gt;

&lt;p&gt;You can have unlimited borrows of a value as long as they're all immutable. Once something is borrowed as mutable, it can only be borrowed as mutable once and the original owner can't be used until the mutable reference goes out of scope. Borrowing rules ensure safe, conflict-free access, preventing data races and other concurrency nightmares.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fn main(){
    let s = String::from("hello");
    let t = &amp;amp;s; // t borrows s
    println!("{}", s); // This is fine because t is an immutable borrow
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In conclusion, Rust's memory management model, with its concepts of ownership, borrowing, and lifetimes, is a powerful tool that provides both safety and efficiency. However, this is just the tip of the iceberg. There's much more to explore and understand about Rust's memory model and its implications for concurrent and systems programming. As you delve deeper into Rust, you'll discover how these concepts interplay to provide a unique blend of performance, safety, and zero-cost abstractions. Keep exploring, keep learning, and enjoy the journey into the fascinating world of Rust.&lt;/p&gt;

</description>
      <category>rust</category>
      <category>ownership</category>
      <category>borrowing</category>
      <category>memory</category>
    </item>
  </channel>
</rss>
