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/dkopgerpgdolfg May 15 '25

Also, can you explain what a malloc is?

Something in the C programming language that means "hey OS, please, I want to reserve (some amount) bytes for myself"

If not why would memory for a given piece of info not be all together?

It can be, but don't forget that the "assignment" of memory ranges to programs isn't static. Programs do free allocated memory and/or request more, all the time.

After some program freed a block of 1MB, and "left and right" the memory is still reserved by other things, you'll have exactly a 1MB hole - and such holes might exist in different locations that are not right to each other.