Introduction
Memory management is the part of the operating system responsible for keeping track of every byte of RAM: which parts are free, which parts are in use, and which process owns each part. Without it, two processes could overwrite each other's data, a buggy program could crash the whole machine, and memory would leak away until nothing was left. The memory manager sits between the CPU's addressing hardware and the physical DRAM chips, translating the addresses a program thinks it uses into the addresses that actually exist.
Cricket analogy: A scorer tracks exactly which overs each bowler has used and how many remain, preventing two bowlers from claiming the same over; the memory manager similarly tracks every byte of RAM so two processes never overwrite the same location.
Explanation
Two addresses matter here. A logical address (also called a virtual address) is the address generated by the CPU while a program runs; it is what the compiler and the program 'see'. A physical address is the actual location in RAM. The Memory Management Unit (MMU), a hardware component, converts logical addresses to physical addresses at run time, using data structures such as base/limit registers, page tables, or segment tables that the OS maintains. Binding of instructions and data to memory addresses can happen at compile time, load time, or run time; only run-time (dynamic) binding allows a process to be moved in memory after it starts, which is what modern OSes rely on.
Cricket analogy: A batsman calls for a run based on where they perceive the fielder to be (logical address) versus the fielder's true position (physical address); the MMU is like the third umpire reconciling perception with reality via replay data (page tables).
Example
#include <stdio.h>
int global_var = 42; /* lives in the data segment */
void show_addresses(void) {
int local_var = 7; /* lives on the stack */
int *heap_var = malloc(sizeof(int)); /* lives on the heap */
*heap_var = 99;
/* These are all LOGICAL (virtual) addresses. */
/* The MMU maps each one to some physical frame that */
/* the process itself never needs to know about. */
printf("global_var address: %p\n", (void *)&global_var);
printf("local_var address: %p\n", (void *)&local_var);
printf("heap_var address: %p\n", (void *)heap_var);
free(heap_var);
}Analysis
Every pointer printed above is a virtual address inside this process's own address space. Two different processes running the same program simultaneously will print the exact same virtual addresses, yet the MMU maps each to a different physical frame, so the two copies never collide. This separation is what lets the OS run many programs 'at once' safely, relocate processes in physical memory transparently, and enforce protection so one process cannot read or write another's memory.
Cricket analogy: Two identical training drills run simultaneously on adjacent pitches will call out the same drill numbers (virtual addresses), yet they're physically different patches of grass (physical frames), so the drills never interfere with each other.
Key Takeaways
- The MMU translates logical (virtual) addresses generated by the CPU into physical addresses in RAM.
- Address binding can occur at compile time, load time, or run time; only run-time binding allows relocation.
- The logical address space of a process is independent of, and usually different in size from, physical memory.
- Memory management provides protection (isolating processes) and enables efficient sharing of physical RAM.
- Contiguous allocation, paging, segmentation, and virtual memory are all strategies built on top of this basic address-translation idea.
Practice what you learned
1. Which hardware component translates a logical address into a physical address at run time?
2. When is a process free to be relocated in physical memory after it starts executing?
3. What is a 'logical address' in the context of memory management?
4. Why can two different processes running the same program have identical logical addresses but not collide in memory?
Was this page helpful?
You May Also Like
Contiguous Memory Allocation
Allocating each process a single unbroken block of physical memory, and the fragmentation problems that follow.
Paging
Splitting logical and physical memory into fixed-size pages and frames to eliminate external fragmentation.
Virtual Memory Concepts
The abstraction that gives each process its own address space, which can be larger than physical RAM.