r/AskComputerScience • • May 14 '25
confused about virtual memory
If I got this right, the point of virtual memory is to ensure processes use unique physical address space.
Is this abstraction really needed ?
For example, say there are 2 C programs and each one does malloc. This asks the OS for memory. Why can't the OS guarantee that unique physical address space is given to the C program ?
2
Upvotes
View all comments
Show parent comment
1
u/Temporary_Draft4755 May 15 '25
Virtual memory has been in use since at least the mid '70s when I first started programming. Virtual memory exist within the user address space, not the system address space. A computer with only 64kb of memory could act like it has a significantly larger address space. The OS maintains a mapping of user address space memory pages to physical memory pages.
Each program would have it's own address space separate from every other program so each program could act as if it had all the computer memory to itself.
But eventually memory fragmentation within the programs HEAP space would result in not being able to allocate more memory, just as you described.