If the user's system has at least 2 megabytes of extended memory available and an 80386 microprocessor, then Windows and Windows applications will run in 386 enhanced mode. In this mode, by taking advantage of certain features of the 80386 processor, Windows implements a virtual-memory management scheme using disk swapping. The result of this scheme is that the amount of memory available to all applications can be several times the amount of extended memory on the system. In this mode, Windows can theoretically address 4 gigabytes of memory, but is limited by the amount of RAM and disk space available for swapping.
Note:
Because 386 enhanced mode uses the protected-mode features of the 80386 processor, the restrictions for using memory in standard mode also apply to using memory in 386 enhanced mode.
The following describes the memory configuration of 386 enhanced mode:
The global heap is essentially one large virtual address space shared by all applications.
The size of the global heap's virtual address space is not bounded by the amount of extended memory. The disk serves as a secondary memory medium that extends the virtual address space.
The 386 enhanced-mode fixed code and data segments are located lower in memory than nondiscardable, movable code and data segments, and discardable data segments, which are allocated above the fixed code and data segments. Discardable code segments are allocated from the top of memory.
The 386 enhanced-mode memory configuration is distinct from standard mode, because Windows swaps code and data between physical memory and the disk. In standard mode, Windows may remove discardable data from memory, but it does not save the data to disk so that it may be read back into memory when needed.
In 386 enhanced mode, Windows continues allocating physical memory until it is used up, and then begins swapping 4K pages of code and data from physical memory to disk in order to make additional physical memory available. Windows swaps 4K objects (pages), rather than unequal-sized code and data segments. A swapped 4K object may be only part of a given code or data segment, or it may cross over two or more code or data segments.
This memory swapping, or paging, is transparent to the application. If the application attempts to access a code or data segment of which some part has been paged out to disk, the 80386 microprocessor issues an interrupt, called a page fault, to Windows. Windows then swaps other pages out of memory and restores the pages that the application needs. Windows chooses the pages that it swaps to disk based on a least-recently-used (LRU) algorithm.
This virtual-memory system provides as much additional memory as the size of the Windows swap file that is reserved on the user's disk. Windows determines the size of the swap file based on the total amount of physical memory on the system and the amount of disk space available. The user can modify the size of the swap file by changing an entry in the SYSTEM.INI file and can establish a permanent swap file by using the swapfile command.
The Windows demand-loading of code and data segments operates on top of the Windows virtual-memory paging scheme. That is, Windows treats virtual memory as though it were conventional memory for purposes of determining which code and data segments to discard. Windows, however, removes discardable code and data segments only when virtual memory is exhausted.
Occasionally, it is necessary to ensure that certain memory is always present in physical memory and is never paged to disk. For example, a dynamic-link library (DLL) function may be required to respond immediately to an interrupt instead of waiting for the system to generate a page fault and load the data from the disk. In such cases, a memory object can be page-locked to prevent it from being paged to disk.
To page-lock a memory object, call the GlobalPageLock function, passing it the global selector of the segment that is to be locked. This function increments (increases by one) a page-lock count for the segment; as long as the count for a given segment is nonzero, the segment will remain at the same physical address and will not be paged out to disk. When you no longer require the memory to be locked, call the GlobalPageUnlock to decrement (decrease by one) the page-lock count. In standard mode, these functions have no effect.
Note:
You should page-lock memory only in critical situations. Do not routinely page-lock memory to lock down a spreadsheet, for example. Page-locking memory adversely affects the performance of all applications, including yours.