Grades 9–12 · Computing
How can two programs use the same memory address without sharing the same data?
A program usually works with virtual memory addresses rather than choosing physical RAM locations directly. Each process has its own address space. A page is a block of addresses that can be mapped as a unit. For an ordinary paged translation, hardware uses the virtual page number to find a physical page, while keeping the offset that identifies the particular location within that page. The operating system arranges the mappings used for the current process.
In the diagramThe same virtual address can map to different pagesProcess A: 1000Process B: 1000map Amap Bpage 2page 5physical RAMInvented mappings: translation and permissions organize access.
Two programs can therefore both use virtual address 1000 while reaching different physical pages. The number has meaning within its address space. This resembles two buildings each having a room 12: the room number alone does not identify one unique room across the whole city.
Page mappings also carry permissions, such as whether code may write to a region. An access to an unavailable or forbidden page can trigger a fault for the operating system to handle. A missing page may require data to be brought into RAM, while an invalid access can cause the program to be stopped.
Virtual memory is more than using a storage drive as extra RAM. It also supports relocation, controlled sharing and separation between processes. Storage-backed paging is one possible part of that system and can be much slower than a RAM access. The abstraction organizes access; it does not create unlimited fast physical memory.
About this explanation
Starting knowledge: Understand memory addresses, a running process, binary values and a mapping between identifiers.
Sources
- Microsoft Learn — Virtual Address Space and Physical Storage
- Microsoft Learn — Context Switches
- The Linux Kernel documentation — Process Addresses: Page tables