HIMEM.SYS, EMM386 and the 640 KB problem
MS-DOS programs expect to run in the first 640 KB of memory. Every driver and resident program takes a slice of that space. HIMEM.SYS and EMM386 exist to move as much as possible out of it, and the four memory types are enough to fix most "out of memory" errors.
The four memory areas
Conventional memory is the first 640 KB. DOS itself, drivers and programs all compete for it. A program that refuses to start usually needs a larger free block there, not more total memory.
Upper memory is the region between 640 KB and 1 MB. It is reserved for hardware, but unused parts can be remapped as UMBs, upper memory blocks, where drivers and resident programs can live.
Extended memory (XMS) is everything above 1 MB. HIMEM.SYS manages it and provides the high memory area, the first 64 KB above 1 MB, where DOS can place part of itself.
Expanded memory (EMS) is a bank-switched window, traditionally in upper memory, that lets programs address more than 640 KB in 16 KB pages. EMM386.EXE emulates EMS using extended memory.
A sample CONFIG.SYS
The usual order matters: HIMEM.SYS first, then EMM386, then the devices you want to load high.
DEVICE=C:\DOS\HIMEM.SYS DEVICE=C:\DOS\EMM386.EXE NOEMS DOS=HIGH,UMB FILES=30 BUFFERS=20 DEVICEHIGH=C:\DOS\MOUSE.SYS
DOS=HIGH,UMB puts part of DOS above 1 MB and makes upper memory available. Replacing NOEMS with RAM enables both UMBs and an EMS page frame; use NOEMS when no program needs EMS, because the page frame costs 64 KB of upper memory.
DEVICEHIGH and LH
DEVICEHIGH in CONFIG.SYS and LH in AUTOEXEC.BAT both try to load a driver or program into a UMB instead of conventional memory. They only work if EMM386 is loaded and UMBs are enabled with DOS=UMB. If a driver fails to load high, DOS falls back to conventional memory, so the machine still boots.
MEMMAKER, available from MS-DOS 6.x, automates this tuning by trying combinations and rewriting the two files. On 5.00 the work is manual.
When EMM386 helps and when it hurts
EMM386 is needed when a program requires EMS, which is common for older games and some CAD and spreadsheet software. It is also needed for DEVICEHIGH and LH to have anywhere to put things.
It gets in the way on a 286, where it cannot run, and on machines where nothing needs EMS and upper memory is already sufficient. If everything runs and MEM shows enough free conventional memory, EMM386 only costs a driver and boot time.
Checking the result
MEM prints a summary of conventional, upper, extended and expanded memory. MEM /C adds a list of loaded programs and drivers grouped by the region they occupy, which is the fastest way to see what is still in conventional memory. MEM /F shows free regions instead.
Read the largest free block, not the total. A program that needs 580 KB will not start if the total is 600 KB but fragmented into 400 KB and 200 KB pieces. Removing one resident program or moving it high often solves it.
Memory and a bootable USB stick
A stick prepared with MBFUTool 2.0 boots into a BEN menu, and the DOS tools it launches run inside the same 640 KB. If a tool reports insufficient memory, the fix is in CONFIG.SYS on the image: move drivers high, drop anything unnecessary, and keep the image lean.
Step by step
- Back up CONFIG.SYS. Copy CONFIG.SYS and AUTOEXEC.BAT somewhere safe before you change the memory configuration.
- Load HIMEM.SYS first. Add DEVICE=C:\DOS\HIMEM.SYS as the first device line, then add DOS=HIGH,UMB.
- Decide on EMS. Use NOEMS unless a specific program needs expanded memory, in which case use RAM.
- Move drivers high. Change DEVICE= to DEVICEHIGH= and add LH in AUTOEXEC.BAT, then reboot and check MEM /C.
Questions
Do I need EMM386 if I have plenty of RAM?
No. Without EMS-hungry software, NOEMS or no EMM386 at all gives you more upper memory for drivers.
Why does my program still say out of memory?
It needs a large contiguous block in conventional memory. Check MEM /C and move residents high or remove them.
Can HIMEM.SYS run on a 286?
Yes, and it is how DOS gets loaded above 640 KB there. EMM386 requires a 386 or later.