Virtual Memory?

mikeshn

Senior member
Oct 9, 2001
367
0
0
Why CPU need the Virtual Memory? The CPU has physical memory. What is the purpose of Virtual Memory?
Thanks
 

erikiksaz

Diamond Member
Nov 3, 1999
5,486
0
76
Ahh, i think we have this in the FAQs somewhere. But anyways, the CPU has "memory," but i don't think RAM necessarily counts as belonging independently to the CPU. The main purpose of VM is that when you run out of ram (yes, believe it or not, it still happens, even with 1+ gigabyte ram counts), the allocated VM (on the hard drive) will be used as ram, so you don't get one of those "out of memory" errors.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
Virtual Memory is needed for proper memory protection, memory mapped files, process seperation, letting processes think they have 2G (on 32-bit arches) of memory when that's not possible and many other things.

But the pagefile is probably what you're asking about and it's main function is a repository to dump old and infrequently used memory pages to disk so more physical memory can be freed for other things. There are other things it's used for, but that's the thing most people know it for.
 

AndyHui

Administrator Emeritus<br>Elite Member<br>AT FAQ M
Oct 9, 1999
13,141
17
81
Didn't I answer this for you last time????

All modern 32-bit versions of Windows allow programs to see, and have available to them, the entire addressable memory range for a 32-bit x86 processor: 4GB of RAM.

Obviously this is far more than the amount of physical RAM in your system. Even so, programs are allowed up to 4GB of RAM. With that much available for use, evidently the overflow from your physical RAM has to go some where. In such a case, Windows' virtual Memory Manager will allocate pages of RAM to disk, ie the swap file.

Since accessing information from the hard disk is much slower, the idea is to keep regularly used information in RAM, and try to use the swap file on the hard disk as little as possible.....or at least, that is what a good virtual memory manager will do. It follows then that the more RAM you have, the less data will overflow your physical RAM and need to be paged from disk.
 

AndyHui

Administrator Emeritus<br>Elite Member<br>AT FAQ M
Oct 9, 1999
13,141
17
81
OK...let's explain it another way.

An Intel or AMD processor (x86), can talk to up to 4GB of RAM. The operating system (say Windows 9x/ME/NT/2K/XP), works by assuming that you have up to 4GB of RAM. This 4GB is "virtual", because you don't really have 4GB of RAM in your system. You are more likely to have something like 256MB.

So what happens if the OS thinks you have 4GB of RAM, but you only have 256MB worth of RAM actually sitting in the system? The overflow has to go somewhere. This is where the swap file comes in.

For example:
Windows wants to use 320MB of RAM, but you have 256MB of DIMMs. Where does the remaining 64MB go? It's located in the swapfile.