Classic Computer Magazine Archive COMPUTE! ISSUE 138 / FEBRUARY/MARCH 1992 / PAGE 6

Managing your PC's memory. (includes related articles)
by Dan Gookin

As technology drags a reluctant DOS into its second decade, one of the issues PC users face is memory management. And thanks to a lack of Darwinian evolution, the procedures for dealing with memory are downright gross. Thankfully, memory managers exist to give you control over the megabytes of RAM most PCs now contain. DOS legitimized the process when version 5.0 came out. But that doesn't simplify the problem.

In order to understand memory management, you need to know how memory is used in a PC. Further, you need to acquaint yourself with some of the strange terms used to describe memory--primarily the differences between extended and expanded memory and why one is more useful than the other. Then comes learning the memory management techniques that finally help you get your full hardware dollar value under DOS.

Memory in Your PC

Everything starts with the traditional memory map, as shown in figure 1. All PCs, regardless of their microprocessors, have two main areas of memory: conventional memory, which is also called DOS memory, and upper memory, which is sometimes referred to as reserved memory. Together these two areas constitute the basic one megabyte of memory used in all PCs.

Why only one megabyte? Because that was the design of the original PC. Its 8088 microprocessor could only access 1MB of RAM. Further, it could only use that memory in 64K chunks. Therefore, the basic 1MB memory map is divided into 16 banks of 64K each, numbered 0 through 9, then A through F (see figure 1).

IBM designed the bottom ten banks of memory--10 x 64K or 640K of memory--for use by DOS and for running programs. That was then times the amount available in competing CP/M computers of the early 1980s--a truly massive amount for a personal computer. The rest of the memory, the 384K that makes up the upper memory area, was devoted to future expansion: ROM BIOSs, video systems, network adapters, and so on.

This would all work great, and everyone would be happy save for two things: People wanted their PCs to do more, so programs got bigger, and new PC microprocessors appeared that could access more than the 8088's paltry 1MB.

Extra Memory in Your PC

For a program to do more, it requires more memory. After a short time, PC applications grew in size, quickly reaching the 640K "brick wall." There is no way around that problem; 640K was and is the max for all DOS programs, period. Several work-around solutions were developed, such as memory resident programs, also called TSRs (for Terminate and Stay Resident), that allow software to pop up at the press of a key. But the only lasting and practical way to give DOS applications more memory was expanded memory. (Keep that thought warm for a second.)

The other problem with the 640K limit surfaced with the new, powerful microprocessors hardware manufacturers began tossing into PCs. First the 80286 could access up to 16MB of RAM, 16 times the original PC's limit, and later the 80386 raised the roof to 4096MB, or four gigabytes, of RAM. All that extra memory is referred to as extended memory.

Extended memory sounds like a dream come true: acres of ready RAM. The problem is that DOS cannot use extended memory to run programs; all PCs--regardless of their microprocessors--are stuck with the same 640K limit as the old 8088 when they run DOS. Therein lies the rub: To be compatible with DOS and its volumes of programs, you have to all but ignore your PC's extended memory.

Welcome to the first hurdle to understanding memory management. There are two types of extra memory in a PC, expanded and extended. Of the two, expanded memory is the best solution for DOS programs that need extra memory. Extended memory is useful, but under DOS it's merely a name given to any extra memory (above the 1MB mark) in an 80286 or later PC. Table 1 lists the differences, but up front you should remember that for DOS programs, it's expanded memory you want.

Expanded Memory

Expanded memory is basically an extra hunk of memory in your computer--something like another hard drive, only it's memory. To put this memory into an 8088 or 80286 computer, you need to add an expanded memory adapter card, such as the AST RAMPage! or Intel AboveBoard. For 386 PCs, you create expanded memory by using a device driver to convert your extended memory into the more useful expanded memory. (That trick can also be done with some 80286 systems, specifically those with the NEAT or AT/386 CHIPSet fro

On the software side, expanded memory is controlled using the Expanded Memory Specification, or EMS. Since expanded memory was developed by Lotus, Intel, and Microsoft, the


standard is referred to as LIM 4.0 EMS. The 4.0 refers to the version, which presently allows for up to 32MB of expanded memory in a PC.

Since expanded memory isn't a part of the PC's basic memory layout, it must be accessed through a special area of memory called the page frame. That's a 64K chunk of upper memory that contains four 16K pages. Eeach page contains memory that can be copied to expanded memory or that was read from expanded memory (see figure 2).

The page frame and all of expanded memory are controlled by the EMS device driver. That's how your software accesses the extra memory. So when you're working on that massive 1-2-3 spreadsheet, you have no way of knowing that it's really using some 4MB of expanded memory for storage. All the technowizardly is handled by the 1-2-3 software working with the EMS device driver.

The page frame sounds rather inefficient and inelegant. After all, looking at 32MB of memory via a 16K page is limited. However, your hard drive is accessed only 512 bytes at a time. And working with memory is much quicker than working with a mechanical hard drive, so expanded memory can really be quite zippy. To augment the process, LIM 4.0 EMS also gives you a giant 384K page frame in conventional memory. This allows for major movement of data to and from expanded memory, and it's how task swappers like Software Carousel and DESQview move programs into and out of memory at the touch of a key.

Expanded memory is the true solution for extra memory under DOS and with DOS applications. All PCs can have expanded memory, and most programs that could use a few kilobytes of extra memory will support expanded memory. Fortunately, there are only a few acronyms and silly terms to learn: EMS, LIN,and page frame. But unfortunately, memory management doesn't end here.

Extended Memory

Extended memory is an often cursed at and confusing element of memory management. Basically, extended memory is extra memory above the 1MB mark on 80286 or later PCs. Whenever you add memory to those systems, you're adding extended memory. (On an 80286, you add expanded memory via an expansion card.)

The unfortunate part is that DOS can't run programs in extended memory. To use extended memory, your PC must run in its protected mode. DOS is an 8088 or real mode operating system. If you have OS/2, UNIX, or Xenix, which are protected mode operating systems, then extended memory is required. But under DOS, extended memory is a white elephant.

Don't write off extended memory just yet! It can still be used under DOS for data storage, RAM drives, and disk caches. And on 386-level systems, extended memory can be converted into expanded memory. This all starts with an extended memory driver, such as HIMEM.SYS, which comes with DOS 5.

HIMEM.SYS controls extended memory via the Extended Memory Specification, or XMS. That's a set of rules for accessing extended memory just as the EMS is a set of rules for working with expanded memory. When HIMEM.SYS or a similar XMS driver is loaded by CONFIG.SYS, it controls all of your PC's extended memory and establishes the XMS standard. This is the first step in 80286 and 386 memory management: Control your extended memory.

Part of the XMS specification creates what's known as the HMA, or High Memory Area (see figure 1). This is a bonus 64K bank of memory that DOS can directly use. Thanks to a quirk in the 80286 and later microprocessors, DOS can see the first 64K of extended memory. That bank--the HMA--was originally used by Windows, but under DOS 5 it can be shared between DOS and Windows and help save conventional memory.

HMA is the last of the acronyms you need to learn to understand memory on a PC. The others are EMS and XMS. And the different types of memory are conventional, upper, expanded, and extended memory. Between expanded and extended memory, expanded is more useful for DOS. And the bottom line for everything, technical terms aside, is that a system with an 80386-level microprocessor opens more doors for you than any other type of PC. This becomes apparent when you start managing all that memory.

Managing Memory with DOS 5

There are three steps to memory management under DOS 5: The first is to establish control over extended memory, creating the HMA with HIMEM.SYS and loading DOS into that area. Next comes creating upper memory blocks, or UMBs, and optionally converting over any expanded memory. Finally, there's loading high, which is the process of moving device drivers and memory resident programs (TSRs) into upper memory blocks.

This is important, but it can be confusing. The object of DOS memory management is to free up as much conventional memory as possible, giving your applications more breathing room. Follow along closely, and refer to the sample CONFIG.SYS file in figure 3.

Figure 3

1: REM This is a typical DOS 5 CONFIG.SYS file. 2: 3: device=c:\dos\himem.sys 4: dos=high, umb 5: device=c:\dos\emm386.exe noems 6: 7: devicehigh=c:\dos\ansi.sys 8: devicehigh=c:\mouse\mouse.sys

The first memory manager in your DOS 5 CONFIG.SYS file is HIMEM.SYS (refer to figure 3, line 3). HIMEM.SYS controls extended memory, sets up the XMS standard, and creates the HMA. In order to do all that, you need to have an 80286 or later PC with at least 350K of extended memory (any 1MB machine will do).

Given that HIMEM.SYS is in control, your next step is to load DOS into the HMA. This frees up 40K to 50K of conventional memory, making that much room available to your applications. The command DOS=HIGH in CONFIG.SYS does the job (figure 3, line 4).

If you have an 80286-level system, this is where DOS 5 stops. You've freed up some 50K of conventional memory, but that's all DOS 5 can do for your machine. If you have an expanded memory card in your system, your next step would be to load your EMS driver (EMM.SYS or something similar), followed by a third-party memory manager, if you have one. Otherwise, the 80286 choo-choo stops here.

On a 386 system, the next step is to create upper memory blocks, or UMBs. These are unused areas of upper memory--that 386K of reserved future expansion memory in all PCs (see figure 1). IBM was quite liberal in giving the PC 384K; in most systems, half of that space is empty. To use it under DOS 5, you can install the EMM386.EXE device driver. (Yes, it ends in EXE even though it's a device driver.)

EMM386.EXE will fill in the cracks of upper memory, putting useful RAM into the unused spaces. Those areas of memory then become the upper memory blocks. This is done by installing the EMM386.EXE device driver into you CONFIG.SYS file, along with its NOEMS option (figure 3, line 5). Note that EMM386.EXE must come after HIMEM.SYS is installed.

In addition to installing EMM386.EXE, you also need to tell DOS that there will be UMBs. The command DOS=UMB does that in your CONFIG.SYS file. Since DOS is already equal to HIGH, you can simply stick a comma at the end of the command and then add UMB (see figure 3, line 4).

Once the UMBs are created, you can load device drivers and memory resident programs into them. This frees up conventional memory dramatically; with all your 4K, 10K, and 25K device drivers in the upper memory area, you'll have that much more conventional memory available to your programs.

The command to load device drivers high is DEVICEHIGH. It's used in CONFIG.SYS exactly like the DEVICE command. (See figure 3, lines 7 and 8.) The LOADHIGH command is used at the DOS prompt, or more likely in AUTOEXEC.BAT, to load memory resident programs into UMBs. Just put LOADHIGH, or its abbreviated form LH, in front of any memory resident program you want to load high. Here's an example.


In the example above, the LOADHIGH command will put the DOSKEY keyboard macro program into a UMB. Note that any options that would normally follow the TSR in AUTOEXEC.BAT or at the DOS prompt are still specified; the only addition is LH or LOADHIGH inserted before the program's name.

You can load high all you want. Consider bringing out older TSRs and device drivers you didn't think you had the RAM for and using them once again. (Hello, Sidekick!) DOS will load each of them high until there are no more UMBs. When you run out, DOS will load the program low as it did before. You can use the MEM command with the /C switch to see which programs are loaded into UMBs and which are loaded low. (Note that HIMEM.SYS and EMM386.EXE cannot be loaded high.)

Together, all these commands carry out DOS's memory management to the fullest--provided you're a Windows user. Windows wants and needs extended memory to run. If it sees one byte of expanded memory, Windows blanches and won't run in its powerful 386-enhanced mode.

If you don't use Windows or if you'd like some expanded memory for the DOS applications on your 386, then you can use the EMM386.EXE device driver to convert some or all of your extended memory into expanded memory.

Figure 4

1: REM This is another DOS 5 CONFIG.SYS file. 2: 3: device=c:\dos\himem.sys 4: dos=high, umb 5: device=c:\dos\emm386.exe 1024 ram 6: 7: devicehigh=c:\dos\ansi.sys 8: devicehigh=c:\mouse\mouse.sys

Figure 4 is almost identical to the CONFIG.SYS file in figure 3. The EMM386.EXE device driver line is a bit different, however (line 5). First, the value 1024 is specified, and second, the RAM switch is used instead of NOEMS. Otherwise, everything is identical.

The value 1024 after EMM386.EXE indicates that 1MB, or 1024K, of extended memory is to be converted into expanded memory. By default, EMM386.EXE wants to convert 256K of extended memory into expanded. It can convert any value you specify, from 16 on up to 32768 for 16K through 32MB, but usually is limited by the amount of extended memory you have to begin with. Any memory you don't convert remains as extended memory for programs that need it.

The RAM option is basically the same option as NOEMS; both cause EMM386.EXE to create UMBs. The difference is that RAM is used when expanded memory is created. NOEMS directs EMM386.EXE not to create any expanded memory. (Therefore, NOEMS is only used in situations where only extended memory is required, such as when running Windows.)

This wraps up what DOS can do with its memory management abilities. It's not bad considering how much more conventional memory you'll have. But it does require a lot of work on your part, editing CONFIG.SYS and AUTOEXEC.BAT to set everything up and load your programs high. If that bothers you, then you should consider the blessings that third-party memory managers offer.

Third-Party Memory Managers

DOS 5 provides a lot of solutions that already existed out in third-party products. Memory management is one of them. While DOS 5 now does memory management, and not too badly, third-party memory managers have been around much longer and do things much more neatly--and automatically. If the bottom line excites you, then know that third-party memory managers often give you an extra 20K to 30K of conventional memory over what DOS provides.

Up front, third-party memory management setup is automatic. Your system is analyzed and customized by a series of tests and self-resets. There's no need to toil with editing CONFIG.SYS or AUTOEXEC.BAT ever. When you make changes to the system, you simply rerun the optimization utility that came with the memory manager. Everything is set up for you. It's really painless.

If you want to go beyond the basics, the third-party memory managers also give you greater control over your memory. Special options let you customize how memory is used beyond what the automatic installation programs can do. These include options to control shadow memory, include or exclude certain parts of upper memory to work around special expansion cards, or really give you a memory boost by taking advantage of unused video memory.

Stealing video memory is one sure-fire way to break through the 640K barrier. For example, if you have an EGA or VGA graphics adapter, you can surrender its high-resolution graphics memory to DOS, adding an extra 64K or 96K to conventional memory. That ups the ceiling from 640K to 704K or even 736K. Wow! Most programs immediately recognize and greedily gobble up the extra memory--more than they would ever have otherwise. But this trick isn't without cost: Any graphics programs or applications that use a graphic screen (such as WordPerfect's Print Preview) won't work; you'll just get plain CGA color text.

Presently, two powerhouse memory management packages are available for 386 systems: 386MAX (Qualitas, Suite 1386, 7101 Wisconsin Avenue, Bethesda, Maryland 20814; 301-907-6700; $99.95) and QEMM (Quarterdeck, 1901 Main Street, Santa Monica, California 90405; 213-392-9851; $99.95). Both offer automatic installation and optimization, extensive options for customizing memory on your system, and 100-percent compatibility with DOS 5, Windows, and DESQView.

Bottom Line

Memory management is going to be a major DOS theme for quite some time to come. The problem has been around since the first spreadsheet users hit their heads on the 640K barrier, and it will be with us until DOS (or its successor) offers a smooth method of accessing extra memory without headaches. Until all these problems are solved, there will be terms to learn, acronyms to identify, and various interesting things to work out in CONFIG.SYS and AUTOEXEC.BAT.

But the best part about memory management is that once you've set up your PC, you can forget about it. With the proper memory managers installed and the system tested, you can get on with your work and enjoy all the hardware and memory you've paid for. Soon you'll be swimming in RAM.