Learning Question
Why does each process appear to have its own memory if all processes share the same physical machine?
A process does not normally use raw physical memory addresses directly.
It uses virtual addresses inside its own process address space.
The operating system and hardware memory-management unit translate those virtual addresses to physical memory or other backing storage.
The first mental model is:
A process sees a private virtual address space. The OS and hardware map parts of that space to real memory, files, or nothing at all.
Virtual Addresses Are Process-Relative
When a program uses an address, that address is meaningful inside the current process.
The same numeric virtual address in two different processes does not automatically refer to the same physical memory.
Each process has its own mapping from virtual addresses to underlying resources.
This is why two processes can both have a stack, heap, code region, and shared library mappings without overwriting each other’s ordinary private data.
The address value is not enough by itself.
The process context matters.
Address Space as a Map
A process address space is not just one large block of allocated memory.
It is closer to a map of ranges.
Some ranges may be:
- executable code
- read-only data
- writable data
- heap memory
- stack memory
- shared library mappings
- memory-mapped files
- intentionally unmapped gaps
When the process accesses a virtual address, the system checks whether that address belongs to a mapped region and whether the access is allowed.
If the address is unmapped or the access violates permissions, the process may fault.
On Unix/Linux, an invalid memory access commonly becomes a segmentation fault.
Isolation Through Address Spaces
Virtual memory gives each process isolation.
If process A writes to its heap, it should not accidentally overwrite process B’s heap.
The hardware enforces this by translating virtual addresses according to the active process’s address space configuration.
When the CPU switches from one process to another, the active address translation context changes too.
This is one reason context switching is not merely changing which instruction runs next.
The CPU must resume execution with the right process memory view.
Virtual Memory Does Not Mean Infinite Memory
Virtual memory can make address spaces look large, but it does not create unlimited resources.
Mappings still need physical memory, file backing, swap, or delayed allocation behavior.
A process may reserve address space without immediately consuming physical memory for every page.
It may also fail to allocate or fault later if the system cannot provide the needed backing.
This distinction matters:
An address range can exist as a virtual possibility before every byte has been backed by physical memory.
The Heap and Stack Are Regions, Not Special Physics
Programmers often talk about “the heap” and “the stack” as if they were physical places.
At the OS level, they are regions in the process address space with particular uses.
The stack usually grows and shrinks as function calls and thread execution require.
The heap is used by allocators for dynamic allocation.
Both depend on virtual memory mappings.
The details vary by operating system, runtime, and allocator, but the boundary is stable:
The process uses virtual addresses. The OS and hardware decide how valid regions are mapped and protected.
Sharing Is Explicit
Virtual memory also allows controlled sharing.
Two processes may map the same shared library code.
They may map the same file.
They may intentionally share memory for IPC.
But this sharing happens through mappings managed by the operating system.
It is not the default result of two processes using the same virtual address number.
Private mappings and shared mappings are different agreements with the OS.
Core Mental Model
Virtual memory separates the addresses a process uses from the physical memory and backing resources underneath.
That separation supports isolation, protection, sharing, lazy loading, memory-mapped files, and flexible process layout.
When reasoning about a memory address, ask:
Which process owns this virtual address, what region is it in, and what mapping backs it?
Final Summary
Each process appears to have its own memory because it uses a process-specific virtual address space.
The operating system and hardware translate virtual addresses, enforce permissions, and map address ranges to physical memory, files, shared resources, or no valid backing at all.