Memory Management

In Windows 95 and NT, each process has its own address space that enables it to address up to 4 gigabytes (GB) of memory. This means that Windows allocates 4 GB of memory addresses, not actual physical memory. The actual physical memory is limited to the available system resources (RAM and disk space). Windows allocates 2 GB of memory addresses to each application. Another 2 GB of memory addresses are reserved for the kernel.

Most systems are not equipped with 4 GB of physical RAM. Because of this, Windows uses virtual memory. With virtual memory, Windows can transfer some contents of physical memory onto the hard disk when the amount of physical RAM becomes low. This is known as swapping .

click to view at full size.

Figure 1.6 How Windows allocates virtual memory to applications

The virtual addresses used in a process do not represent actual physical locations in memory. Instead, the kernel maintains a page map for each process. A page map is an internal data structure used to translate virtual addresses into physical addresses.

Virtual Memory

Processors from the 80386 on can map memory locations to any 32-bit address. Windows virtual memory uses this capability to allow each program to behave as if it had its own physical RAM.

Windows uses a 32-bit linear addressing scheme to access memory. When an application attempts to access memory, it simply specifies a 32-bit memory address. Each program has its own virtual memory address space, which is mapped by a virtual memory manager onto a memory address. These addresses point to locations in RAM or on a hard disk.

Paging

Physical storage and the virtual (logical) address space of each process are organized into pages, which are units of memory whose size depends on the host computer. For example, on x86 computers the host page size is 4 kilobytes (KB). To maximize its flexibility in managing memory, the kernel can move pages of physical memory to and from a paging file (Pagefile.sys) on a disk. When a page is moved in physical memory, the kernel updates the page maps of the affected processes. When the kernel needs space in physical memory, it moves the oldest pages of physical memory to the paging file. The kernel's manipulation of physical memory is completely transparent to applications, which operate only in their virtual address spaces.

* To see the effects of paging with the Performance Monitor

  1. From the Windows Start menu, point to Programs , Microsoft Visual Basic 5.0 and click Visual Basic 5.0 .
  2. Click the Existing tab and select the Lab1.vbp project in WA \ Labs\Ch01 folder. Click Open .
  3. When prompted to Add this project to SourceSafe , click No .
  4. Open the code window for the cmdUseRAM_Click event and review the Visual Basic code.

    This procedure will fill an array with space characters using a large amount of memory.

  5. Open the code window for the cmdFreeRAM_Click event and review the Visual Basic code.

    The Erase statement is used to re-initialize the array, HugeArray . HugeArray has been declared in the General Declarations section of the form.

  6. Run the application.

    This will open the System Monitor automatically.

  7. In System Monitor , from the Options menu, click Chart .
  8. Set the Update Interval to the fastest setting, then click OK .
  9. From the Edit menu select Add Item .
  10. From Category , select Memory Manager and from Item , select Allocated Memory and click OK .
  11. Repeat Step 8 for the Memory Manager item, Swapfile in use .
  12. In System Monitor , from the View menu, click Always on Top .
  13. From the View menu, click Bar Charts .
  14. Resize System Monitor so you can see the Visual Basic application at the same time.
  15. In the Visual Basic application, click Use RAM .

    Notice the increase in swap file activity and memory usage.

  16. When you click the Free RAM button, the resources will be freed.
  17. Stop the Visual Basic application and close System Monitor .
  18. Exit Visual Basic.


Microsoft Windows Architecture Training
Microsoft Windows Architecture for Developers Training Kit
ISBN: B00007FY9D
EAN: N/A
Year: 1998
Pages: 324

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net