Urgent.News

What's breaking now, across thousands of outlets.

Tech

What Actually Happens Between malloc() and Physical RAM: Virtual Memory, Page Faults, and the MMU

When you call malloc(100 * 1024 * 1024) in C, new byte[100 * 1024 * 1024] in C#, or allocate a massive buffer in Node.js or Go, how much physical RAM did your machine just allocate? Almost every junior developer answers: 100 megabytes. The real answer is zero bytes. Your operating system handed your process a promise written on virtual paper. Not a single transistor in your DRAM sticks holds your…

When you allocate memory in C using malloc(), Node.js with allocate(), or Go's allocation, the OS doesn't immediately give you physical RAM. It simply promises you a chunk of virtual memory. Your process doesn't own any physical RAM yet. The only thing you have is a promise written in virtual memory. If you check how much memory your process is using in tools like top or /proc/self/status, you'll see that virtual memory size has increased by the requested amount, but resident set size (RSS) remains at 0 KB. Physical memory is only assigned when your CPU actually tries to read or write that first byte.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

I found the Clash of Clans API and ended up building a war simulator

I was looking for something to build and came across the Clash of Clans developer API. I didn't have a particular problem I wanted to solve.

  • Developer builds WarOracle to simulate Clash of Clans wars
  • Uses Monte Carlo simulations for win/loss/draw probabilities
  • Open-source project available at https://waroracle.me

More from Sunday 27 September →