Article ID: 91088 - View products that this article applies to.
This article was previously published under Q91088
When you start your computer, HIMEM.SYS allocates all available extended memory by default. It then manages the use of this memory by other applications with the extended memory specification (XMS).
How HIMEM.SYS Allocates Memory for ItselfHIMEM.SYS uses IBM ROM BIOS interrupt 15h to determine how much extended memory is available. It then uses the same interrupt to set the available extended memory to zero. This prevents other applications from allocating extended memory once HIMEM.SYS has started managing memory. (If you run other programs that allocate extended memory by using interrupt 15h, use the /INT15= switch. For more information, refer to the "User's Guide" for Windows 3.1.)
After setting the available extended memory to zero, HIMEM.SYS assigns handles to each free memory block. On a machine with 4 megabytes (MB) of random-access memory (RAM), the memory starting at 1 MB up to the 4-MB boundary is usually contiguous. In this situation, HIMEM.SYS assigns only one handle to this memory block. More handles are assigned on machines with multiple memory blocks, such as Compaq machines that have a small amount of memory starting at the 16-MB boundary.
Note: HIMEM.SYS does not allocate any memory until another program makes an XMS function call. SMARTDrive and RAMDrive make XMS function calls when they are loaded. The "DOS=HIGH" statement in the CONFIG.SYS file also makes an XMS call. This call requests the use of the high memory area (HMA) and forces HIMEM.SYS to allocate extended memory.
How HIMEM.SYS Allocates Memory for ProgramsHIMEM.SYS gives memory to programs that request it by making a call to an XMS function. It first looks for a large enough block to serve the memory request. Because some machines have more than one block, there is no way to determine which block will be used first.
When HIMEM.SYS finds a large enough block of memory, it divides the memory block into two, which allows the program to use the memory it requested and leave the remainder as a new smaller memory block. The memory allocated to the program starts from the bottom of the block and extends until the memory request is fulfilled. The new block, created from the extra memory, starts where the memory request stopped.
Interrupt 15h MemoryInterrupt (or function) 15h always allocates memory starting from the top of memory moving downwards. Before HIMEM.SYS starts, interrupt 15h sets the starting location or address of extended memory at the top or highest extended memory address. When the amount of available extended memory lowers, the starting address also lowers. After HIMEM.SYS starts, if no interrupt 15h memory was allocated, HIMEM.SYS sets the starting address to the 1-MB boundary (the bottom of extended memory).
Interrupt 15h does not manage memory the same way that HIMEM.SYS does. Interrupt 15h is a large group of several functions for accessing extended memory. Programs actually take control of interrupt 15h by inserting a small piece of code into a table that tells the system where interrupt 15h is located. This is known as creating a hook. Each program that wants extended memory creates a hook and adds some code to report how much memory is available. Programs report the initial available memory minus the amount they decided to use. HIMEM.SYS, when it starts, is no different. It adds a hook that tells all other programs that no extended memory is left. HIMEM.SYS then doles out memory to those programs that know how to use XMS functions, such as SMARTDrive, RAMDrive, and Windows.
Isolating Memory Areas with SMARTDRV.SYS and RAMDRIVE.SYSBy using SMARTDrive from Microsoft MS-DOS 5.0 and RAMDrive from either Windows or MS-DOS, you can roughly determine whether or not a block of RAM is causing problems. This can be very useful for tracking down problems such as memory parity errors.
Although the HIMEM.SYS memory allocation scheme does not allow you to determine which memory it allocates at any given time, you can use features of SMARTDrive and RAMDrive to perform a rough memory test. SMARTDrive allows you to create a cache limited only by the amount of extended memory available. It also lets you set two sizes for the cache, one for MS-DOS and one for Windows. RAMDrive also allows you to allocate a large amount of extended memory, but it does not have the dual size capabilities of SMARTDrive.
By using SMARTDrive from MS-DOS 5.0, you can load SMARTDrive before RAMDrive in the CONFIG.SYS file. You can then tell SMARTDrive to create an MS-DOS cache size of some large amount of memory and a Windows cache size of zero. When you start Windows, SMARTDrive reduces its cache size to zero. Because RAMDrive installs after SMARTDrive, this leaves a gap of unused memory at the bottom, which enables you to test the lower half of extended memory. You can check the top half by simply installing RAMDrive and nothing else.
To clarify this process, review the following step-by-step example, which explains what happens in extended memory as Windows and the various device drivers load. This example is for a machine with 4 MB of memory that is running MS-DOS 5.0 and Windows 3.1 and has frequent memory parity errors: