What is virtual memory and how is it different than RAM?

364 views

What is virtual memory and how is it different than RAM?

In: 41

11 Answers

Anonymous 0 Comments

Most/all modern systems have a piece of hardware in the CPU that lists what memory address ranges in RAM a program is allowed to access, what the *actual* RAM location is, and what the rules are (eg: read-only areas, no-code areas, etc). The operating system loads it with a table of memory allowed by the currently running program, and the program runs by constantly replacing memory addresses the program thinks it uses with actual RAM locations from this table. This is done by the hardware, and programs aren’t aware of it happening. Violations, by either trying to access memory not listed, or violating the rules assigned, will stop the program and the operating system will intervene.

When which program is running changes, the table contents are swapped out for one appropriate to the newly running program. There’s even a table for the operating system itself.

Normally not having an entry in the table, or breaking a rule, will crash the program. However the operating system can *intentionally* leave out entries or tighten up their rules just so that the hardware will inform it when memory is accessed. Memory that has been swapped out of RAM and saved to disk can be loaded back into RAM when the program tries to access it. A single copy of memory can be shared among multiple programs as long as it is read-only; if a program tries to write to it, we can duplicate the memory region and make it writeable after the fact, preserving the original for all other running programs using it.

RAM is a real thing, and all programs need it. Virtual Memory is this table, gatekeeping the RAM, protecting memory that doesn’t belong to you, and also protecting you from other programs.

You are viewing 1 out of 11 answers, click here to view all answers.