Facebook Pixel

Overlays in Operating Systems

Today, if you want to run a 10 GB video game on a laptop with only 8 GB of RAM, you rely on Virtual Memory to automatically swap pieces of the game in and out of the hard drive. But Virtual Memory requires complex hardware (like an MMU) and sophisticated OS support.

In the early days of computing, memory was incredibly scarce, and that hardware did not exist. Programmers still needed to run massive applications on tiny machines. To do this, they used a manual technique called Overlays.

What are Overlays?

Overlays are a programming technique where the programmer manually divides their application into independent modules. Modules that are never needed at the exact same time are designed to share the exact same physical region of memory.

Instead of the Operating System managing what goes where, the application itself contains the logic to load and unload its own pieces as it runs.

How Overlays Work

To make overlays work, a program must be structured with a Root Module (sometimes called the Overlay Driver). This root module is loaded into memory first and stays there permanently. It acts as the manager.

When the program reaches a certain phase, the Root Module fetches "Overlay A" from the disk and loads it into memory. When Phase A is finished, the Root Module fetches "Overlay B" from the disk and loads it directly on top of Overlay A, completely overwriting it.

text
Example Overlay Memory Map:

Total Program Size: 250 KB
Physical RAM Available: 150 KB

The programmer divides the application:
- Root Module (Manager): 50 KB
- Phase 1 (Data Entry): 100 KB
- Phase 2 (Data Sorting): 100 KB

Execution:
1. Root Module loads. (Memory used: 50 KB)
2. Root loads Phase 1. (Memory used: 50 KB + 100 KB = 150 KB)
3. Phase 1 finishes.
4. Root loads Phase 2 exactly where Phase 1 was sitting. (Memory used: 50 KB + 100 KB = 150 KB)

Result: A 250 KB program successfully ran in only 150 KB of RAM!

Advantages of Overlays

  • Hardware Independence: It required absolutely zero special hardware (no Memory Management Unit required). It was entirely implemented in software by the programmer.
  • Overcoming Limits: It was the only way to run massive software (like early word processors and compilers) on heavily restricted systems like MS-DOS or early embedded microcontrollers.

Disadvantages (Why it Died)

  • Extreme Programmer Burden: The Operating System provided no help. The programmer had to intimately understand the memory map, perfectly design the overlay modules, and manually write the complex logic to swap them in and out without crashing.
  • Maintenance Nightmare: If the programmer updated Phase 1 and accidentally made it 110 KB, it would exceed the memory limit and break the entire overlay structure, requiring a complete redesign of the software's architecture.
  • Slow Execution: Manually stopping the program to pull modules from a slow disk disk resulted in significant performance bottlenecks.

Summary

Overlays were a brilliant, manual hack to bypass the severe memory limitations of early computers. However, because they placed a crushing burden on software developers, the technique became completely obsolete the moment modern Operating Systems introduced automatic Virtual Memory.

Overlay Memory Calculation

Question 1 of 1

Test your understanding of how overlays share memory space.

A program consists of a Root module (20 KB), Module A (30 KB), Module B (50 KB), and Module C (40 KB). Modules A, B, and C are mutually exclusive (they never run at the same time). What is the MINIMUM amount of physical RAM required to run this entire program using overlays?
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.