You misunderstand what virtual memory does.
Also known as the Swap file, virtual memory allows a computer to treat secondary memory as though it were the main memory. If the OS has to swap data between virtual memory and RAM too often, it can make the computer feel very slow -- this is called
thrashing.
A system using virtual memory uses a section of the hard drive to emulate RAM. With virtual memory, a system can load larger programs or multiple programs running at the same time, allowing each one to operate as if it has infinite memory and without having to purchase more RAM.
While copying virtual memory into physical memory, the OS divides memory into pagefiles or
swap files with a fixed number of addresses. Each page is stored on a disk, and when the page is needed, the OS copies it from the disk to main memory and translates the virtual addresses into real addresses.
Virtual Memory has its Limitations
- The use of virtual memory has its tradeoffs, particularly with speed. It's generally better to have as much physical memory as possible, so programs work directly from RAM or physical memory.
- The use of virtual memory slows a computer because data must be mapped between virtual and physical memory, which requires extra hardware support for address translations.
- The size of virtual storage is limited by the amount of secondary storage, as well as the addressing scheme with the computer system.
- Thrashing can happen if the amount of RAM is too small, which will make the computer perform slower.
- It may take time to switch between applications using virtual memory.