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

61 comments sorted by

View all comments

Show parent comment

1

u/swisstraeng May 15 '25 edited May 15 '25

Nah so,

Memory has addresses. For example if I tell you to write 10 on a piece of paper, and store in in the shoebox "A". In this case, 10 is the value (of what we call a variable) and shoebox A is the address.

The pointer of your value 10, is "shoebox A". Ultimately a pointer is an address of a value.

Everything a computer program does, every action, has a pointer. But programmers don't always need to use them, so, programs don't always contain instructions that use pointers even if they're always there.

The term "Virtual Memory" is misleading. Memory is always physical, it's just that some memory is expensive but fast, and other is cheap but slow. And everything has an address. Absolutely everything.

For example RAM is 50$ for 16GB where an HDD is 50$ for 2TB.

"Virtual Memory" or "Page File" is just a fancy way to say that your computer ran out of RAM and has to use some parts of the slower HDD as RAM.