Course Content
Part 1: The Basics of RAM
Random Access Memory is one of the most fundamental elements of modern computer.
0/2
Part 5 – Operating Systems and RAM
Now, we are switching gears. Instead of looking at RAM only as little circuits, we are going to see it from the software side — that is, how the operating system (the big boss software like Windows, macOS, Linux, or Android) uses RAM to run programs smoothly.
0/3
Let’s Understand Random Access Memory: The Key to How Your Computer Thinks Fast

Quick Recap Before We Start

In the last part of the course, we learned about hardware-level details of RAM: how RAM works electrically, how it talks to the CPU, and why it is fast but also temporary.

Now, we are switching gears. Instead of looking at RAM only as little circuits, we are going to see it from the software side — that is, how the operating system (the big boss software like Windows, macOS, Linux, or Android) uses RAM to run programs smoothly.

 

Step 1: What Happens When You Open a Program?

Imagine you click on your favorite game or open Microsoft Word. What actually happens inside the computer?

At first, your program is just sitting on your storage device. This could be:

  • a hard disk drive (HDD), which is slower and works like a spinning record player, or

  • a solid-state drive (SSD), which is much faster but still not as quick as RAM.

When you double-click the program, the operating system has to load it into RAM.

Why? Because the CPU (the brain of the computer) cannot directly run programs from the disk. The disk is way too slow. The CPU wants super-fast access, and only RAM can give that.

Think of it like this:

  • Your hard drive is like a giant bookshelf where all the books (programs) are stored.

  • RAM is like your desk.

  • The CPU is like you, the reader.

If you want to read and write notes quickly, you don’t run back to the bookshelf every second. Instead, you bring the book you need to your desk. That’s exactly what the operating system does: it moves the program from disk (bookshelf) into RAM (desk).

This moving process is called loading a program.

 

Step 2: How a Program Looks Inside RAM

Okay, so the program is now in RAM. But it’s not just one neat block. Programs are split into different sections when they’re loaded.

Here’s a breakdown:

  1. Code Segment – This is the actual list of instructions (like “add two numbers” or “draw a pixel”) that the CPU must follow.

  2. Data Segment – This is where fixed data lives, like numbers or words that are already written inside the program. For example, if your game always starts with 3 lives, that number is stored here.

  3. Heap – This is a flexible memory area used for things that grow and shrink while the program runs. For example, when you open a new tab in your web browser, it asks the operating system for more heap space.

  4. Stack – This is a memory zone used for “short-term notes” while the CPU works. Every time a function (a small block of code) is called, the CPU keeps track of it using the stack.

So inside RAM, your program is not one single blob. It’s neatly divided into these different areas.

Think of it like a kitchen:

  • The recipe book is the code.

  • The ingredients already laid out are the data.

  • The fridge and pantry are the heap, where you can store things as needed.

  • The cutting board where you chop things step by step is the stack.

Without this organization, the program would be complete chaos.

 

Step 3: Running – When Programs Compete for RAM

Now, here comes the tricky part.

You rarely have only one program open. You might be running a game, have a web browser open, and maybe music playing in the background.

All of these programs need RAM at the same time. But RAM is limited. What if you only have 8 GB of RAM and all your programs want 12 GB?

This is where the operating system plays referee.

It makes sure that each program gets a fair share of RAM. But it also does something smart:

  • If one program is not being used actively, the operating system can move part of it out of RAM and back into storage temporarily.

  • Then, when you return to that program, it swaps it back into RAM.

This process is called swapping (sometimes also called paging, which we will cover in detail in Lesson 20).

It’s kind of like musical chairs 🎶.

  • The chairs are RAM slots.

  • The players are programs.

  • The operating system makes sure that the most important players (the ones you’re using right now) always have a chair.

  • If the room gets too full, it moves someone to the side (storage) to make space.

 

Step 4: Example – Playing a Game and Checking Email

Let’s say you’re playing a video game that uses a lot of RAM. At the same time, you get an email notification.

  • The game is in RAM, using maybe 4 GB.

  • The email app is also in RAM, using maybe 200 MB (megabytes).

  • The operating system notices that the email app is not very active, so it keeps most of its data safely on disk. Only a small part is in RAM.

  • When you switch to the email app, the operating system quickly swaps some parts of the game out, and brings the email app fully into RAM.

This swapping is so fast (when managed well) that you hardly notice it — unless your RAM is too small. Then your computer starts to feel “slow” because it keeps swapping back and forth too much.

This is why having more RAM makes computers feel “snappier” — because more programs can live in RAM without being constantly moved around.

 

Step 5: The Role of the Operating System

Let’s summarize what the operating system does when it comes to RAM:

  1. Loading – Moves programs from storage to RAM so the CPU can run them.

  2. Allocating – Divides RAM into neat blocks (code, data, heap, stack).

  3. Sharing – Makes sure multiple programs can use RAM fairly without stepping on each other’s toes.

  4. Swapping – Moves programs in and out of RAM when space is tight.

Without the operating system managing RAM, your computer would instantly crash the moment two programs tried to use the same memory spot.

It’s like having a teacher in a classroom. If students (programs) all tried to sit on the same chair (RAM space) without rules, there would be chaos. The teacher (operating system) makes sure everyone has a place to sit.

 

Step 6: What Happens When RAM Runs Out?

When RAM runs out, two things can happen:

  1. Swapping gets too heavy. If the operating system keeps moving programs in and out of storage too much, your computer slows down a lot. This is often called “disk thrashing.”

  2. Program crashes. If a program asks for more RAM than the system can possibly give, it may just stop working. You might have seen this with a web browser that says, “Out of Memory.”

This is why modern operating systems try to be very smart. They constantly monitor which programs you’re using and which ones are idle, so they can balance things smoothly.

 

Step 7: A Peek Ahead

In this lesson, we learned about loading, running, and swapping. But what if RAM is simply not enough, no matter how clever the operating system is?

That’s where virtual memory and paging come in — which we’ll explore in the next lesson. Virtual memory is like pretending you have more RAM than you actually do, by cleverly using storage space.

0% Complete