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

358 views

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

In: 41

11 Answers

Anonymous 0 Comments

Every application you run needs some amount of short-term storage space to store its working state. Every variable a program uses, every image or audio file it loads, every string of text it generates, is stored there, accessed by a unique numerical address. This short term storage space is called memory.

RAM is a physical component in your computer that can be used for memory. If that runs out, a storage disk (HDD or SSD) can be used for additional “virtual” RAM, but it’s much slower. The process of moving memory data from RAM to disk is called Paging or Swapping (the implementation details between the two are different, but that’s not important).

The operating system is in charge of allocated memory to an application. As an application runs, it asks the computer for a certain amount of memory space, or frees up some if it’s no longer needed. When an application runs, the OS presents to it an abstract, contiguous space of memory addresses unique to the program that comprises both the physical and virtual RAM.

The benefit of virtual memory is that:

1. the application doesn’t have to worry about where the data physically exists, the OS manages it
2. the OS can optimise resources by paging unused memory to disk
3. it segregates memory spaces for security, meaning one process generally can’t access the memory of another process (and accidentally corrupt it, or steal data)
4. it allows each program to access memory at a specific address without conflict, eg. two applications can store a variable at “memory address 0x004A” and there won’t be any issue since the underlying data is physically mapped to somewhere else, each program has its own memory mapping

Be aware that sometimes people use “virtual memory” to refer specifically to the virtual RAM component (disk space used as memory with swapping/paging techniques) rather than the higher concept of a virtual address space.

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