What is the purpose of virtual memory?
"Virtual" memory is computer memory that exists on a fixed media
and non-volitile storage device of some kind -- a hard drive, or a
solid state drive -- which is used, mostly, for overflow from, or
swapping things in and/or out of, regular Random Access Memory
(RAM).
The computer comes with three kinds of memory in it: Read-only
Memory (ROM), Random Access Memory (RAM), and the "virtual" memory
that's created by the operating system on a hard drive or solid
state drive.
Hard drives, and/or solid state drives, in and of themselves,
are not considered "memory." They're considered mass storage.
However, once the operating system is up and running on the
computer, and has allocated parts of itself, and of the various
programs that are running, into RAM; and has also allocated a
certain amount of RAM for calculating and doing things, then it
will also allocate a little bit of one of the mass storage devices
-- usually a hard drive, but on some of the newer machines with
solid state drives in them, it can also be on that -- for what's
called "virtual" memory, which is mostly used for RAM overflow...
more specifically, for swapping things in and out of RAM.
The computer reads from ROM (usually the BIOS and CMOS chips) at
startup so that it even knows that it's a computer; and then, from
there, what it has connected to it, and how to use it all.
Then, once the computer has fully booted-up, the operating
system loads parts of itself (and some other things) into RAM, and
then it allocates part of mass storage as "virtual memory." As RAM
starts getting full, the operating system will take the least-used
things in RAM and will throw 'em down onto the part of the mass
storage device that has been allocated as "virtual" memory. Then,
if anything in virtual memory becomes needed up in RAM, again, the
operating system will go get it and pull it back up into RAM.
Virtual memory, then, is mostly used as "swap" space. It is not,
then, actual "memory," per se; but it certainly functions like
it.
Virtual memory is also slower than regular RAM: Data cannot
possibly be put onto, or pulled from, the "virtual" memory part of
a hard drive full of moving parts as fast as it can be moved around
RAM, itself. Even a solid state drive, which is a little like RAM
in the sense that it's an integrated circuit with no moving parts,
is not as fast as RAM. But the operating system knows how to keep
things moving, and to only swap things down into virtual memory
that really and truly won't be needed as much or as often or as
quickly. The virtual memory management parts of most operating
systems is pretty sophisticated.
So, then, the answer to the question, "what is the purpose of
virtual memory," is that virtual memory (which is always a part of
a mass storage device, allocated by the operating system) is
primarly used to swap things in and out of RAM so that said RAM
won't get so clogged-up and bogged-down.
When one purchases a computer, one reads certain specs about it.
For example...
The "processor" (or CPU) may be "dual core" and
three-point-something gigahertz (GHz) in speed; or,
The memory (or RAM) will be 4, 6, 8, 12 or 16 (sometimes more,
sometimes less) gigabytes (GB) in size; or,
The hard drive (mass storage) will be 500 to 750 gigabytes (GB)
(or even one terrabyte, or larger) in size; and, sometimes,
There could also, optionally, be a solid state drive (also
considered mass storage) of 32 or 64 GB.
"Virtual" memory is always allocated by the operating system
from space on either or both of the hard drive or solid state drive
mass storage devices; and said operating system then "swaps" things
to/from RAM down to/from the allocated "virtual" memory; thereby
keeping RAM from becoming cluttered and slow.