Memory and MS Windows Real Mode The following information was obtained from Microsoft Online services. -------------------------------------------------------------------- | INFORMATION PROVIDED IN THIS DOCUMENT AND ANY SOFTWARE THAT MAY | | ACCOMPANY THIS DOCUMENT (collectively referred to as an | | Application Note) IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY | | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO | | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A | | PARTICULAR PURPOSE. The user assumes the entire risk as to the | | accuracy and the use of this Application Note. This Application | | Note may be copied and distributed subject to the following | | conditions: 1) All text must be copied without modification and | | all pages must be included; 2) If software is included, all files | | on the disk(s) must be copied without modification (the DOS | | utility DISKCOPY is appropriate for this purpose); 3) All | | components of this Application Note must be distributed together; | | and 4) This Application Note may not be distributed for profit. | | | | Copyright 1990 Microsoft Corporation. All Rights Reserved. | | Microsoft and the Microsoft logo are registered trademarks of | | Microsoft Corporation. | -------------------------------------------------------------------- REAL MODE WINDOWS 3.00 ====================== Real Mode and Conventional Memory --------------------------------- Windows 3.00 in real mode is similar in most respects to Windows/286 versions 2.x. Real mode Windows 3.00 executes entirely within conventional memory. It requires 384K of free conventional memory (393,216 bytes reported by CHKDSK) to start up successfully. Real Mode and the 384K Reserved I/O Address Space ------------------------------------------------- Windows 3.00 does not access the 384K reserved I/O address space directly in real mode. Remember though, if an external EMM is present (such as EMM386.SYS), the EMM will use areas of the 384K reserved I/O address space. NOTE: Windows 3.00 real mode operation is similar in most respects to Windows/286 versions 2.x. Real mode can use most Windows 2.x device drivers and runs applications written for Windows 2.x. Real Mode and Expanded Memory ----------------------------- SMALL VERSUS LARGE PAGE FRAME MODE Real mode Windows 3.00 will automatically switch into large page frame mode when 280K (plus or minus 8K) of free, mappable expanded memory pages in conventional memory are available after all Windows code has been loaded. The ending position of Windows code in memory plus the amount of Windows global memory determine the start of free expanded memory pages. Global memory is a memory segment that Windows puts aside to store things that need to be globally available to all applications, such as printer drivers and fonts. The point at which the free mappable expanded memory pages begin is called the EMS line. ADJUSTING THE EMS LINE There is no way to set the position of the EMS line explicitly, because real mode Windows sets it automatically, as discussed above. However, you can adjust the EMS line position in a manner relative to its current position with the command line parameters discussed below. REAL MODE WINDOWS EXPANDED MEMORY COMMAND-LINE PARAMETERS The /N Switch Starting real mode Windows with the /N command-line switch disables real mode Windows' use of expanded memory for banking of Windows applications. This effectively eliminates an EMS line. The /N switch does not disable expanded memory but only real mode Windows' use of it. Your external EMM will still be present. A page frame will be established, and applications can still use LIM 3.2 (if a 64K contiguous page frame is present). This means that this switch is not useful for debugging possible expanded memory page frame conflicts. The /N switch disables only real mode Windows' use of expanded memory, not the expanded memory itself. To disable the expanded memory itself, you must remove the external EMM. The /L Switch Starting real mode Windows with the /L+nnn parameter moves the EMS line up or down the specified amount of kilobytes (rounded to 16K increments). The command line WIN/L+16 moves the EMS up 16K, possibly fine-tuning Windows with your system, provided you are already in large page frame. Do not use the /L-16 parameter to move the EMS down, as it will infringe on global memory and cause problems with printing or displaying fonts. Real mode Windows normally starts in large page frame. Start real mode Windows with WIN /L+200 (where 200 is simply an arbitrarily large number) to force real mode Windows to small page frame mode. There is almost never a practical use for any other positive parameter. The /E Switch The /Ennn parameter gives you the ability to adjust the 280K default point at which real mode Windows will go into large page frame mode (see above). Keep in mind that real mode Windows does not automatically use one mode or the other without a good reason. Explicitly setting small or large page frame mode, as opposed to Windows' automatic choice, may cause problems. Windows' automatic choice is usually the best choice to take. However, if you want to explicitly set one mode or the other, you can use this switch. For example, starting real mode Windows with WIN /E100 causes Windows to go into large page frame mode if only 100K of bankable conventional EMS pages are free after Windows code initialization (this effectively switches real mode Windows to large page frame mode). Conversely, starting real mode Windows with WIN /E600 forces small page frame mode in all circumstances. You should normally use the /L+200 switch for this purpose. Real Mode and Extended Memory ----------------------------- CODE CACHING USING EXTENDED MEMORY Real mode Windows 3.00 does not access extended memory directly. However, if extended memory is present and HIMEM.SYS is loaded, real mode Windows can speed its operation considerably by performing code caching to extended memory. All Windows applications are segmented, that is, divided into segments that have certain attributes. These attributes include movable attributes, which means that the segment can be moved around in memory, and discardable attributes, which means that the segment can be discarded (that is, forgotten about, overwritten, and reloaded from disk when necessary). The largest portion of a given Windows application has both the movable and discardable attributes. Under real mode Windows, a lot of discarding goes on because real mode is limited to conventional memory. Windows applications are frequently 600K or larger, much larger than available free memory on a 640K machine with real mode Windows loaded. A Windows application keeps a minimum amount of code loaded in memory; this is known as its swapsize. As the program executes and you choose various functions, whenever Windows runs out of memory, it discards part of the application and overwrites it with new code loaded from the executable file on the hard disk. If XMS memory is accessible to Windows 3.00 via HIMEM.SYS, Windows will effectively discard code to extended memory. Rather than forgetting about the code segment and overwriting it with new code from the executable file, Windows copies the code segment to extended memory. Then, instead of having to reload from the executable file, Windows can fetch the code from extended memory when it is required again. This feature speeds up real mode operation considerably; code caching is not present in Windows/286 versions 2.x. Note that this feature does not replace the Windows SMARTDrive disk caching utility. SMARTDrive should still be loaded whenever possible. USING XMS MEMORY IN DOS APPLICATIONS DOS applications that use XMS memory can also be run from real mode Windows if the required amount of XMS memory is specified in the PIF (Program Information File). One important point about running such applications is that real mode Windows is already using all of the available XMS memory for code caching. Therefore, to run a DOS application PIF that requires XMS memory, you must swap extended memory to disk. For example, assume your machine has 2048K of extended memory. You specify in the PIF that your DOS application requires 1024K of XMS. Real mode Windows is already using all 2 megabytes of extended memory. When you run the DOS application, the first megabyte of XMS memory is swapped to disk, and the DOS application is given access to that megabyte. When you alt+tab back to real mode Windows, the original 1024K of XMS memory is reloaded from disk. Since this process can be slow, you should not request any more XMS memory than is absolutely necessary to run your application. SWAPPING DOS APPLICATIONS TO EXTENDED MEMORY Real mode Windows 3.00 can also swap DOS applications to extended memory. To do this, create a virtual hard disk in extended memory with the RAMDRIVE.SYS driver. Then, set the swapdisk= line in the [nonwindowsapp] section of the SYSTEM.INI file to point to the drive letter that RAMDrive creates. Note that you must have a RAMDrive that is at least three times larger than the largest DOS application you want to use. Also, be advised that using extended memory to create the RAMDrive will reduce real mode Windows' extended memory code caching ability and make it run more slowly. Note: Windows/286 versions 2.x have the ability to swap DOS applications directly to expanded memory. Since expanded memory is rarely used under Windows 3.00, this capability was removed. If you want to swap DOS applications to expanded memory, set up a RAMDrive in expanded memory and swap to the RAMDrive. RUNNING PROTECTED MODE DOS APPLICATIONS Windows real mode allows DOS applications that use a DOS extender technology such as VCPI (Virtual Control Program Interface) to run in protected mode. Extended memory allocation for such applications must be made in the PIF. ms-windows