
                            THANKS FOR THE MEMORY

                          (c) 1995  by Kyle Freeman


  If it hasn't happened to you yet, be assured it will!  You've just
  gotten that new computer loaded with RAM.  Windows is running as
  smoothly as a Mozart minuet; you're multitasking like a carnival
  juggler.  Then one day you try to run some program, probably a great new
  game, and you're greeted with a rude message telling you that you don't
  have enough memory.  You try it again without any other programs running
  and still you get the same message.  "But I've got  eight, or sixteen or
  thirty-two megs of RAM?

  How come I can't run this one program?"

  There are lots of reasons you can run out of memory in Windows,
  especially if you are running DOS programs in a DOS window.  You can
  also run out of resources long before you run out of memory.  But if you
  fail to get past this guardian dragon while running only one program,
  then what you've probably run into are conflicting demands for two types
  of RAM: expanded memory (EMS) and extended memory (XMS).

  Windows programs use XMS but this new game or spreadsheet or flight
  simulator requires EMS, or at least will run better with EMS.  If you
  optimize your machine for Windows, it will use XMS, but if you set it up
  to use EMS, it will usually cost you a big chunk of RAM, which can slow
  Windows performance, sometimes drastically.  How can you get the best of
  both of these memory worlds, without having to buy a second computer?

  There is a way -- two, in fact.  Both require some trade off in
  convenience, but the cost is really minimal.  What follows will explain
  what to do, when in fact,  you have this conflict.  Check the
  documentation of the program that is giving you this out of memory
  message.  If it says that you should use expanded memory with it, then
  what follows, is the solution to your problem.  Or it may be that you've
  already set up your system (or someone else has set it up for you) to
  use EMS, but now you're running into the other side of that coin, and
  your Windows programs don't get enough memory because of the RAM your
  EMS setup is eating.  In short, you can either set up a multi-bootup
  menu or make a special bootup disk. Neither is difficult to do.  I'll
  show you how to do both later on, as we'll go through each step by step.
  But first let's take a quick trip down your computer's memory lane to
  examine the secret life of RAM.

  While Gertrude Stein may have been right that a rose is a rose is a
  rose, RAM would have caused her to think again. Not all RAM is created
  equal. Of course, all your RAM holds little bits of information the same
  way, but the areas it fills and the rules governing those areas differ.
  Lets look at five aspects of RAM, all of which play some part in
  resolving your expanded vs. extended conflict.

  Conventional Memory

  First, as you probably know, no matter how much RAM your computer has,
  the critical number is 640K. Thats the first 655,360 bytes of memory
  that your CPU addresses (1 Kilobyte is 1024 bytes; 640x1024 = 655,360).
  Its called conventional memory, or the lower 640, as opposed to all the
  rest of your RAM, which is above the first 640K. When you run out of
  memory, its usually this lower 640K that youve used up. All your DOS
  programs use this memory, and some Windows programs use bits of it, too.

  Upper Memory Area

  This 640 K limitation came about because Intels first chip, the 8086,
  addressed 1 megabyte of memory in what is now called real mode. When
  IBM designed its first personal computer to use this chip, it decided to
  set aside some of this 1 MB, 384K in fact, for video cards, system ROM
  (Read-Only Memory), BASIC expansion cards, and various other cards. The
  384 Reserved memory message you see when your computer boots up or when
  you check your memory usage by typing mem refers to this area. So
  Microsoft designed its disk operating system (DOS) for IBM to use what
  was left of the original 1 MB, which turns out to be 640K.

  However, this never happens, primarily because using the Reserved area
  that way would be like harnessing Pegasus as a plowhorse.  First, the
  ROM at those addresses is read through your BIOS, which is much slower
  than the speed with which your machine can access RAM.  So to make the
  whole operation much faster, most BIOS's now have the ability to take
  the information stored in those addresses, remap the addresses to RAM,
  and then write the information for those addresses to its new home in
  RAM. Then when your system is looking for something that it expects to
  find in those addresses, it finds it at exactly the address it was
  looking for, but now that address is in RAM.  This is known as
  shadowing.  Videocards and system ROM are the things most usually
  shadowed.

  In addition, as it turns out, machines rarely if ever use all of that
  384K of reserved addresses for the things for which they were set aside.
  Instead, through the use of special software (DOS uses HIMEM.SYS
  andEMM386.EXE), some of those addresses are mapped out as upper memory
  blocks (UMB) that can then be used to load all kinds of things that
  would otherwise be forced to take up some of your lower 640 K.  But
  before we can discuss the creation of UMBs, we have to look at the kind
  of memory from which UMBs are formed.

  Extended Memory

  XMS came about when Intel introduced the 80286 chip, which could access
  16MB of memory. IBM used this chip in its AT class machine, which could
  access XMS. XMS is all the memory that exists above the 1 MB mark. To
  access this memory, programs need to run in what's called protected
  mode. All DOS programs run in real mode and can't access this XMS. For
  one thing, this memory has no addresses. Memory addresses stop at the 1
  MB limit. Windows can use this memory, but its unavailable to DOS
  without some program designed to run in protected mode. HIMEM.SYS is the
  DOS program that coordinates the use of your system's XMS so that
  programs calling for it don't conflict with each other. It also gives
  access to something called the High Memory Area.

  High Memory Area

  Another wrinkle of the 286 chip was its ability to carve out one more
  little space called the High Memory Area (HMA) that DOS could reach in
  real mode. Its the first 64K of memory past the 1 MB limit. By design
  the only things that can be assigned there are DOS itself, the system
  buffers, and the DoubleSpace driver. (Actually, DesqView could fit
  there, too, but Im assuming youre using Windows or you wouldnt be
  having this conflict to start with.) Well come back to this later, as
  filling it properly can have a small but perhaps crucial effect on your
  EMS v. XMS problem.

  Expanded Memory

  To allow DOS programs to use some of this extra memory, Lotus, Intel,
  and Microsoft put their heads together to create something called the
  Expanded Memory Specification (thus the LIM EMS you may have seen).
  Through software managers, like EMM386.EXE, some of that XMS can be made
  to act like ("simulate" is the term usually used) extra, or expanded,
  lower 640K memory, which doesnt require going into protected mode. Thus
  DOS programs can use it as if its an extension of the basic lower 640K,
  which in fact it is.

  But before the alchemy that transforms XMS into EMS, EMM386 must first
  create an area in the first 1 MB of addressable memory that can hold it.
  Naturally, the place to do that is in the 384K of reserved addresses.
  EMM386 looks at all those addresses, finds what isnt being used, which
  is usually a lot, then maps those unused addresses with some of your
  XMS, otherwise unusable by DOS, thus creating the Upper Memory Area. It
  can then put some of your programs that would normally fit in the lower
  640 into these UMBs. This is where your Terminate and Stay Resident
  (TSR) programs are often loaded, as well as sound card, CDROM, and
  network drivers. Windows itself loads its translation buffers there,
  also in a 64K segment. In 386 enhanced mode, Windows allocates buffers
  in the Upper Memory Area to translate MS-DOS & network application
  program interface (API) calls from Windows protected mode to MS-DOS real
  mode.

  In addition to creating the Upper Memory area, EMM386 also manages EMS.
  When a DOS program needs EMS, it calls EMM386, which then creates whats
  called a page frame in the Upper Memory Area that always requires 64K.
  EMM386 takes some RAM from the pool of expanded memory youve asked it
  to use, assigns it to some available addresses in Upper Memory, then
  puts the data from the program there in 16K segments. Only data can go
  in the page frame; executable code cant. EMM386 pages through the data
  as its called by the program that uses the data, until the calls by
  some greedy DOS program exceed 64K. It then looks for other areas in
  Upper Memory in which to write the new data while keeping up with where
  the first 64K worth of calls were allocated. This is called bank
  switching. By means of it, EMM386 can handle several megabytes of data
  by switching these 64K segments.

  This is the core of the conflict between XMS and EMS. Ideally, there
  would be enough free space in the Upper Memory area to place both the
  translation buffers & an EMS page frame. But on many systems theres
  not. If youve set up your system to use all this Upper Memory for your
  TSRs, Smartdrv, your mouse, and whatever else, its usually pretty well
  full up. If you ask EMM386 to use EMS, it must carve out a 64K page
  frame, which will push out many of those TSRs and drivers into the only
  other place they can fit, which is the lower 640K. To deal with both
  heads of this hydra, you can use the multi-bootup capacity built into
  DOS or you can make a special bootup disk. The following assumes youre
  using DOS 6.0 or higher. If youve still got an older version of DOS,
  then my advice is UPGRADE! Its the best $50 you can spend on your
  machine.

  Before we go through these options, however, you should first get your
  system optimized for however you plan to run it most of the time. In
  most cases that will be to run Windows, and therefore you'll want to
  give all your computers memory above 1 MB to EMM386 to use as XMS. To
  do that, put the following line in your CONFIG.SYS file:

  DEVICE=C:\DOS\EMM386.EXE NOEMS

  You probably have such a line already. If it contains some other
  switches after the NOEMS, like X=C000-C7FF, or I=B000-B7FF, leave them
  as they are. They are exclusions and inclusions of UMBs that either are
  or arent being used. EMM386 is instructed to use these addresses to
  provide more UMBs.

  Next, optimize the order in which youve loaded everything in both your
  AUTOEXEC.BAT and CONFIG.SYS. Here are a few helpful tips. First, if you
  plan to use Windows most if not all of the time for this particular
  setup, you dont need to load a mouse driver in AUTOEXEC.BAT. That
  driver only works for DOS programs in DOS. Windows loads a mouse driver
  automatically, so you can save some valuable memory by omitting it here.
  If you must load one, move it up to the top of your AUTOEXEC.BAT file.
  Mouse drivers require a lot of RAM to initialize, nearly 50K, then a
  much lesser amount, usually between 14 and 20K, once installed. Youll
  want your mouse driver to load in upper memory, but if it cant find a
  UMB with about 50K of free space, it will load low, robbing you of much
  needed lower memory. Its got a much better chance of finding that 50K
  if it's loaded first. It will then give back the rest of that 50K it
  isnt using after it initializes so other programs can load high.

  Next, if you're using SETVER.EXE, put REM in front of it. SETVER fools
  older programs that require a specific version of DOS, like 2.0, into
  believing theyve found it. Few programs require it. Youll save some
  memory by excluding it. If you find that something you run needs it,
  then of course you will then have to remove the REM to let it load. But
  in most cases, its simply a memory waster.

  The same is true of the FCBS line you may have. File Control Blocks are
  similar to SERVER. Some older programs require them, but not many. If
  you have a line that sets FCBS=16,0, as an alarming number of systems
  do, quite needlessly, you can safely change it to FCBS=1. COMMAND.COM
  requires one file control block, but its a safe bet that nothing else
  you have needs one. If you have no FCBS line, the value defaults to 4.
  You can save a couple hundred bytes of RAM by adding FCBS=1, but unless
  youre hell-bent to get every last byte of RAM, you neednt go to the
  trouble.

  Too many buffers can take up memory as well. Buffers fit into the HMA,
  along with DOS. Nothing else goes in the HMA, so you want to fill it
  with as many buffers as you can without an overflow into low memory. A
  reliable rule of thumb is to use BUFFERS=40 if you arent using
  DoubleSpace, and 17 if you are.  In DOS6.22, you can check to see how
  much of your HMA is filled by your present buffer setting by entering
  MEM /A.  If the amount of space left in the HMA is several K, you should
  include more buffers until its full. You can also add a little bit of
  Upper Memory by excluding the address set aside for monochrome video. If
  you have a color monitor, youre probably not using this area anyway,
  although its always possible that something you installed has figured
  this out and appropriated it. But probably not. So in your

    DEVICE=C:\DOS\EMM386 NOEMS line, add a space and X=B000-B7FF.

  This will give Windows an extra UMB to fill with TSR's. If you do this, you
  must also add

    DEVICE=C:\DOS\MONOUMB 86 to the [386Enh] section

  of your SYSTEM.INI file in Windows. Make sure you have a file in your DOS
  directory called MONOUMB.386; you might have erased it thinking it did
  you no good. If youre using QEMM or 386MAX as your memory manager, you
  must use a file called MONOUMB2.386.

  DoubleSpace takes up a big chunk of memory, about 50K. Its not
  something youre likely to be able to alter: either you use it because
  you need it, or youve got a big enough drive that you merely smile at
  it in passing whenever you do a search of your DOS directory. If youre
  thinking about using it, be aware that it will make whatever memory
  problems you may have all the more acute.

  One last tip is to check the line of your AUTOEXEC.BAT that loads your
  MS DOS Extender for your CDROM (MSCDEX.EXE). It should look something
  like this:

    LH C:\SB16\DRV\MSCDEX.EXE /D:MSCD001 /L:F /M:20


  The" /M:x" switch usually found there sets aside a number of buffers for
  your CDROM. The x is the number of buffers youre telling your system
  to use. While it would be ideal to have as large a number of buffers as
  possible, those buffers take up lots of RAM. A number between 10 and 20
  is usually optimum. If by some chance your system was set up with a
  number near the limit of your CDROM, such as 64, youre being robbed of
  about 100K of RAM by that little stinker.

  So, after getting these two files in fighting trim, run memmaker (or
  whatever equivalent you might have, e.g., QEMM), make sure no gremlins
  attacked your machine and that everything works as it should, then copy
  these files somewhere safe, and go back to do it all over again. This
  time you want to change the NOEMS switch on your EMM386 line to RAM.

  This will be the setup to use for those programs that require EMS. If
  the documentation for your EMS programs state you need to set aside a
  specific amount of EMS, add that number, in kilobytes, after RAM. For
  example, King's Quest asks for 2 MB of EMS, as I recall, so your line
  would read

               DEVICE=C:\DOS\EMM386.EXE RAM 2048

  Because the RAM switch will set up a 64K page frame in upper memory,
  other things that used to go there will be squeezed out. Since you will
  be using this setup for specialized purposes no doubt less frequently
  than the first one, you can probably jettison some things from your
  AUTOEXEC.BAT and CONFIG.SYS files that you wont use with this setup.

  If, for instance, youll not be using your CDROM or your SoundBlaster
  with the programs that require EMS, don't load those drivers. Its
  doubtful this will be the case, as whatever that new program is thats
  causing your memory problems probably uses one or both. Exclude your
  network drivers if you don't intend for this setup to run over your
  network.

  One thing to change will probably be your FILES= line in CONFIG.SYS.
  Windows uses lots of file handles, but the game or flight simulator or
  whatever may not need near as many. Find out the most files specified in
  the documentation for all of the programs for which you need EMS, and
  set the FILES= line to that number. If none of those programs specify
  anything about files, try using 20. If any-thing hollers, you can bump
  it up as need be. Also look for DEVICE=C:\DOS\ANSI.SYS. Its unlikely
  that youll need ANSI for both of your setups. Leave it out, if you have
  it, for the one that doesnt need flashy prompts or screen colors
  dependent on ANSI.

  Also remove all the LH /L:1,16790 type stuff from all the lines in your
  AUTOEXEC.BAT and CONFIG.SYS Dont remove the rest of the line: just the
  LOADHIGH or LH /L:xxx part. Youre going to rerun memmaker to let it put
  all these things where they can fit after its added a page frame.  And
  of course, if your first setup goes into Windows as the last line of
  your AUTOEXEC.BAT, remove that.

  Now rerun memmaker. Youll get a different set of LH addresses and a
  different amount of free memory. Here is the fun part. You get to choose
  either a multi-bootup setup or a special boot disk. The easiest is
  probably to copy this second set of AUTOEXEC.BAT and CONFIG.SYS files to
  a bootup disk, one that has COMMAND.COM, io.sys, msdos.sys, and if
  relevant, dblspace.bin. You won't see the last three with a directory
  search, as they are hidden, system files, unless you use a comma after
  "dir" when looking. They'll all be in lower case, which is DOS's way to
  show you that a file has the hidden attribute.

  If you don't have a bootup disk, you can make one in a few seconds by
  putting a formatted disk in drive A and typing SYS C: A: and pressing
  Enter. This will copy all your system files to the floppy. Then copy the
  original pair of AUTOEXEC.BAT and CONFIG.SYS files back to your root
  directory after putting the second pair on this disk. Then whenever you
  boot up, youll get the setup optimized for Windows, and whenever you
  want to run your EMS programs, you can reboot using the bootup disk you
  have just created.

  If, however, you tend to lose disks or have so many around you can never
  find the one youre looking for, or people at work come by on a regular
  basis to borrow your disks and dont return them, or for whatever
  reason youd prefer to have this choice of setups on your hard drive,
  theres another way to accomplish this. Its a bit more involved, but it
  works well and its always there for you.

  You'll want to set up a multiboot sequence in your CONFIG.SYS and
  AUTOEXEC.BAT files. To do this, youll need both sets of files youve
  just created. Open an ASCII text editor (you have at least three, if
  youve got DOS 5 or above and Windows: type EDIT at a DOS prompt, or use
  Notepad or Write in Windows). Import your first CONFIG.SYS file. Put
  "[menu]" as the first item in the new CONFIG.SYS, with two menuitem=
  lines under it. (Dont, of course, type in the quotation marks.) The
  menuitem entries will specify the names of the two bootup regimes you
  will use. You can call them anything you want: Standard and Games, or
  Extended and Expanded, or Yin and Yang. It doesnt matter, so long as
  you know what each name means. So you might put

  [menu]
  menuitem=Windows
  menuitem=Games

  Then below those lines add a section called Windows enclosed in
  brackets. Underneath those brackets copy the entire CONFIG.SYS file from
  the first setup you copied into some safe place. It will be the one with
  the EMM386 line that had the NOEMS switch. E.g.,

  [Windows]
  DEVICE=C:\DOS\HIMEM.SYS
  DEVICE=C:\DOS\EMM386.EXE NOEMS
  command
  command
  command

  Then type the other section name below that. Be sure to call it the same
  name you gave the second menuitem. Then copy the entire CONFIG.SYS file
  from the second set of setup files you created earlier. E.g.,

  [Games]
  DEVICE=C:\DOS\HIMEM.SYS
  DEVICE=C:\DOS\EMM386.EXE RAM
  command
  command
  command

  I've found that it's dangerous to make a [common] section, as the DOS 6
  help docs tell you, because DOS executes all the lines in the [common]
  section before it goes to the individual menuitems. Thus, if you try
  putting everything in the [common] section except the EMM386 line, which
  may be the only thing different in your two CONFIG.SYS files, DOS waits
  to do the EMM386 lines last.  It will load all the drivers in the common
  section low, since EMM386 hadnt yet begun to manage any upper memory.
  So Ive found it best to make two complete menuitem sections. Once you
  have the CONFIG.SYS properly divided into the number of setups you want,
  save your CONFIG.SYS file in your editor, and then open up your
  AUTOEXEC.BAT file. Start this AUTOEXEC.BAT file with the line

  goto %config%

  and then have two sections that begin with a colon and the name of the
  two menuitems you defined in CONFIG.SYS. So using the example above,
  your new AUTOEXEC.BAT file should look like this:

  goto %config%
  :Windows
  command
  command
  command
  goto END
  :Games
  command
  command
  command
  goto END
  :END

  Of course, you put underneath the Windows heading all the commands and
  their specific addresses that the first memmaker run gave you for your
  AUTOEXEC, and the second set of AUTOEXEC commands and addresses under
  Games. Youll then get a choice upon bootup thereafter asking you which
  of the two you want to use.

  Whichever you defined first will be the one on which the cursor rests as
  the default, so youll save a keystroke on each bootup if you put first,
  the one you plan to use most often.

  That's all there is to it. You can now laugh in scorn at the memory
  problems that once bedeviled you. You might even think of Bob Hope as
  you hum or whistle "Thanks for the Memory."


  Kyle Freeman, a former college teacher, is now a San Francisco
  consultant. He can be found in the various Windows conferences around the
  nets and can be reached at kyle.freeman@lcabin.com.  Kyle is a WindoWatch
  regular contributor.


                                    ww



