First, let me see if I have the correct understanding about virtual and physical memory. I was under the impression that virtual memory is DRAM (dynamic RAM), free space on the hard drive possibly reserved for the CPU - or the CPU can nab - for temporary use, as a buffer so to speak, on an as-needed basis. (For 128K Mac folks, it is what we once did by hand - disk swaps.)
Likewise, physical memory would be the hard drive itself, correct? Total physical memory would equal the DRAM plus the remaining space (used or not) on the hard drive. Of course, available physical memory would only be remaining free space…not including what could be DRAM, I guess?
Anyway, some clarification with these terms would be a great help. I may need to ask some more detailed questions a little later.
Yes, Cleophus…you have stated what I meant to say based on my understanding. However, your explanation of virtual memory equated to MY understanding of DRAM. So, does DRAM equate to Virtual Memory? If not, then what (exactly) is DRAM?
And, dare I ask for an explanation of cache? Is it just a little added memory buffer…serving what purpose?
Hard disk=not memory. Like you writing something down–you won’t forget it but you have to look it up first. Physical memory=DRAM (a type of memory chip) or SRAM (a different type) or xRAM. The amount of space your CPU can use to store stuff (programs and data). Much like your own memory. Virtual memory=disk space that the CPU uses to fake having more real (physical) memory. Anything that is taking up memory that the CPU judges it won’t need right away gets stored on a special spot on disk and that physical memory space gets used for something else. If the CPU needs the stuff it stored, it knows right where to get it, which is faster than finding it on the hard drive. Like a sticky-note pasted where you can look right at it: slower than actually storing it in memory, but faster than writing it down and putting in it a pile somewhere. Cache=special physical (real) memory built into the CPU where it stores stuff it needs often–so it can get it real quick when needed.
DRAM = Dynamic Random Access Memory. This is the memory that is on your motherboard. It’s called dynamic because it decays very quickly. In fact, your computer has to constantly refresh it, or else it will lose all of its memory contents. This is different than SRAM, which is Static RAM, which does not have to be refreshed.
You can think of DRAM as your physical system memory. If you have 128 MB of RAM, then thats the size of the memory chips on your motherboard.
What happens when you run out of memory? On some operating systems the system just crashes. Windows, Linux, and most other modern operating systems use what is called “virtual memory” where memory pages are stored on the hard drive to free up some of the physical memory. When you start using virtual memory, the system slows down, because pages of data have to be transferred back and forth between the hard drive and the physical memory. The virtual memory on the hard drive is stored in what is called the swap file. Windows keeps the swap in a file with an extension .swp (IIRC). Linux uses a seperate swap partition on the drive. Other operating systems will vary.
Cache is technically just a place to store stuff. Older computers used caches for frequently accessed data just to speed up the overall system. In a PC, a cache is typically just a small fast memory that is close to the processor. It’s faster than the main system memory (DRAM) so its useful for the processor to store stuff in. You might be asking “if it’s faster, how come we don’t make all the memory out of it?” The answer is simple. Your computer would cost too much.
The CPU looks for data in the cache first. If it’s not available there, then it looks in the DRAM. If the data isn’t there then it goes out and fetches it from the hard drive. Each level is a huge slowdown in speed, so optimizing things to keep as much stuff in the caches and DRAM is key to good system performance.
Pentiums have multiple levels of cache, called level 1 and level 2 (L1 and L2). It’s the same idea, using multiple levels of smaller and faster memory to keep frequently used data close to the processor’s execution unit so that it can get to it as quickly as possible.
I’ll try and clarify this virtual memory thing. Virtual memory describes how applications interact with memory. In older OS’es the address I would use to work with memory was the actual address of the chunk of physical memory on the system. So if apps A and B access location 10000 they are both access the same place in ram.(Physical address 10000) In virtual memory each application is given their own “memory space.” You could say I “emulate” a chunk of memory and give it to the app. So when the application does something to say address 10000 under virtual memory they are accessing “virtual address” 10000. There is no telling where that virtual address really is however. The OS maps that access to somewhere else. The big thing is that since the OS is mapping the application’s virtual memory access to somewhere else I can swap things in and out of the “real” memory as needed.(So if I have 256 MB of RAM and my application allocates 512MB I store part of this on the hard drive. When the application asks to use an address that’s currently on the hard drive I swap out stuff from physical memory to the hard drive. However as far as the application is concerned I have the full 512MB at my disposal.) Another thing under virtual memory is that since each application is given their own memory space address 10000 in application A would not point to the same memory as address 10000 in application B.(Virtual addresses are generally unique to the application.)
If you want I can go further on this.(Maybe with a real world example.)