DevPrep

All topics › Memory management

What is virtual memory? Where do code, stack and heap physically live?

Senior PRO

Essence

Every process sees its own virtual address space — a contiguous range of addresses not tied to physical RAM directly. Translation from virtual to physical addresses is done by the MMU via page tables maintained by the kernel (XNU). A page on arm64 iOS is 16 KB.

Why: process isolation (you cannot read another process's memory), protection (code pages read-only + execute, data pages no-execute), lazy allocation (an address is "reserved", physical memory is provided on first touch), and sharing one physical copy of libraries among processes.

The rest of this answer, with code and interview follow-ups, is in the DevPrep app.

Read the full answer in DevPrep

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store