TITLE
    Basic PC Memory Management
Article ID:
Created:
Modified:
56514
7/29/95
3/12/98

TOPIC

    The mystery of memory is explained in this two-part article on memory issues that directly affect the operation of Claris applications. Part one deals exclusively with Windows memory issues.

    This information was provided by Claris Corporation on 16 March 1998, and incorporated into Apple Computer's Tech Info Library.


DISCUSSION

    Do the words "general protection fault" or "application error" put fear in your heart? Does the thought of doing any customizing or editing in MS-DOS fill you with fear? Do you feel you know "just enough to be dangerous" when it comes to handling your Windows computer?

    Errors you may encounter on your Windows computer often have to do with the memory used by your computer to run your applications. As you will see, memory is an organized structure, and not mysterious.

    Disk storage and RAM
    There are two ways that data can be stored on a computer. First, it helps to know that data is anything that you put on your computer. Whether it is an application or a document you just saved, it is all data. The first method of storing data is known as temporary storage, most commonly referred to as RAM (Random Access Memory). This type of memory holds the data until you turn off your computer. The only way to ensure that a document or file in which you were working does not vanish when your computer is turned off is to save the file(s) before powering down your computer.


    The second type of storage is known as permanent. There are many types of storage devices but they generally fall into two categories: hard disk and floppy disk. The data is read from and written to these permanent types of storage devices. A hard disk (also known as fixed disk) is usually installed inside the computer and can hold large amounts of data. A floppy disk is removable and can hold limited amounts of data.

    Unit of measurement
    A bit (short for binary digit) is the smallest unit of information in the binary code. A bundle of eight bits forms what is called a byte. A byte can represent 256 different combinations of zeros and ones (binary code) which form 127 different symbols such as letters, numbers, punctuation marks and special codes. The naming convention used for describing large increments of data includes Kilobyte (K), Megabyte (MB), Gigabyte (GB), and Terabyte (TB). The metric prefixes denote now many bytes of information. The prefix "kilo" means one thousand, "mega" equals one million, "giga" equals one billion and "tera" means a whopping one trillion! A kilobyte is actually slightly larger than one thousand bytes. It actually is 1,024 bytes. Thus, the megabyte is actually 1,048,576 bytes.


    Memory on the PC
    Memory on the PC is a variation of the theme described here. A PC divides its memory into separate blocks, each block being used for different things. You can picture the memory of a PC as a single region, with different types of memory layered on top of each other. (See Figure 1.)

    Conventional memory
    The first layer of memory on every PC running DOS is base or conventional memory. The conventional memory found on all PCs is the first 640 kilobytes of RAM, which can accommodate up to 640K of drivers. While most Windows applications are able to access other types of memory, this block is necessary because a number of programs use a small amount of base memory just to boot up. Also, there are still some programs, primarily DOS applications, which access conventional memory only.

    Upper memory block
    You can think of the memory directly above base memory as a small block known as upper, or high, memory; this is the 384K that, together with base memory totals one megabyte (640K + 384K = 1024K = 1 megabyte). (See Figure 1.) Because the amount of high memory is finite, MS-DOS can load only as many drivers and programs as will fit into that 384K memory range.


    High memory and Extended Memory
    The first 64K of Extended Memory is called High memory. In order to utilize any range of memory, high, extended or expanded, a memory manager must be used. Two files provided with MS-DOS and Windows, when used together, create an effective memory manager. HIMEM.SYS is required for Windows and SMARTDRV.EXE to run. In addition, EMM386.EXE is required for use of the memory area above 640K. The required syntax, as it would appear in the
    CONFIG.SYS file is shown in the following examples. Since MS-DOS 6.0 (and higher) has the most current versions of EMM386.EXE and HIMEM.SYS, it is used throughout the syntax examples here. So, when using MS-DOS 6.0 (or higher) the commands are:

    DEVICE=C:\DOS\HIMEM.SYS
    DEVICE=C:\DOS\EMM386.EXE NOEMS
    DOS=HIGH,UMB

    Please note: When using MS-DOS 5.0, use the HIMEM.SYS and EMM386.EXE which are provided with Windows 3.1 (and higher). This means the lines in the CONFIG.SYS read as follows:

    DEVICE=C:\WINDOWS\HIMEM.SYS
    DEVICE=C:\WINDOWS\EMM386.EXE NOEMS
    DOS=HIGH,UMB


    Do-it-yourself PC memory
    Even in the best of all possible worlds, this can happen to you: you're ready to go to work on that report that's due next week. You turn on your computer, load Windows, load your application and you see an "Out of memory" message on the screen. What do you do now?

    Most of the time, memory errors can mean that not enough conventional memory is available for applications to use. It also can mean that a couple of simple changes need to be made in Windows. A good rule is to have at least 580K of available conventional memory. Although not all applications require that much to start and operate, it is helpful since you will most likely have more than one application running at the same time in Windows.

    There are two files which instruct the computer what files and programs to load, where to find those files and programs and how to load them. These are the CONFIG.SYS and the AUTOEXEC.BAT files.

    The CONFIG.SYS instructs the computer to load and configure the operating environment. The AUTOEXEC.BAT tells the computer what software applications and Terminate and Stay Resident programs (TSRs) to load and how to fine tune the operating environment. When using the memory management system provided with MS-DOS, the commands which instruct DOS to move a device driver or program into the high memory area are DEVICEHIGH in the CONFIG.SYS and LOADHIGH (or LH) in the

    AUTOEXEC.BAT.

    There are three basic things to investigate when an "out of memory" error is displayed when using an application in Windows. These include the examination and adjustment of the of the swap file for virtual memory; checking the amount of conventional memory available; and editing of your AUTOEXEC.BAT and CONFIG.SYS files.

    Before you begin, always backup your files. To make backups of the AUTOEXEC.BAT and CONFIG.SYS files, type the following commands at the C:\ prompt:

    To save the AUTOEXEC.BAT file, type:

    COPY AUTOEXEC.BAT AUTOEXEC.SAV

    Then press Enter.

    To save the CONFIG.SYS file, type:

    COPY CONFIG.SYS CONFIG.SAV

    Then press Enter.

    Examine Virtual Memory swap file size
    Check to see that there is a Windows Permanent Swap File and that it is at least 5MB in size. To check this, open Control Panel, click on the 386 Enhanced icon, click on Virtual Memory and view the displayed description. The second point only applies if you are using Windows for Workgroups. If you are using Windows for Workgroups, open File Manager from Program Manager, and locate the CLARIS.INI file in the Windows directory. Open that file and look for the line which reads: "Cache Size=xxx" (where "xxx" is a number). Edit this line so that it reads:

    Cache Size=0

    Save the file and close File Manager. Now, close Windows.

    Check amount of available conventional memory
    At the C:\ prompt, type the following command:

    MEM

    Press Enter.

    On the resulting display, examine the value labeled "Largest Executable Program Size." This value is the amount of available conventional memory. That part of the 640K range which is not being used by anything. The number should be around 580K. If this number is below 580K, you will want to examine and edit your AUTOEXEC.BAT and CONFIG.SYS file, so that as many as possible device drivers and programs are loaded high. For example, in the CONFIG.SYS file you may have a line like the one below:

    DEVICE=C:\DOS\SETVER.EXE

    The correct syntax which will instruct MS-DOS to remap the file into the high memory area (assuming your system is using MS-DOS 6.0 or higher) is as follows:

    DEVICE=C:\DOS\HIMEM.SYS
    DEVICE=C:\DOS\EMM386.EXE NOEMS
    DOS=HIGH,UMB
    DEVICEHIGH=C:\DOS\SETVER.EXE

    In the AUTOEXEC.BAT file, there may be a line which reads something like:


    C:\MOUSE\MOUSE.COM

    This can be loaded high by using the following command:

    LH C:\MOUSE\MOUSE.COM

    Please note: Any changes you make to these files do not take effect until you reboot your computer.

    General Protection Fault
    A memory error
    A General Protection Fault (GPF) fault signifies that something unexpected has happened within the Windows environment, usually an improper memory access. In other words, something running within the Windows environment has made a call to a location in memory that it should not have had access to, potentially overwriting and corrupting other program code in that area of memory. An application or Windows component might read or write to a memory location that it has not been reallocated, or memory that it does not "own."
    Another situation where a GPF fault may occur involves the passing of parameters between applications and the Windows environment. Invalid parameters affect the performance of Windows and its applications by forcing an invalid instruction. This is usually the result of an application's internal program code incorrectly passing specific data that could not be correctly interpreted for Windows or another Windows application. The result is often a GPF fault, or it may "lock up" your system or give any of numerous other error messages.


    General Protection Faults and Video
    GPFs might also be occurring because of a video driver memory conflict. Try the following if you suspect a memory conflict.

    1. Exclude video memory X=A000-C7FF from the EMM386 line in your config.sys file so that it reads:
    Device=C:\DOS\EMM386.EXE X=A000-C7FF NOEMS
    2. Try a different driver, such as Windows VGA. To change the video driver go into Windows Setup (found in the Main group) and change the system setting for Display to VGA. You may need your original Windows disks to this.

    The quick test for this kind of conflict is to boot your computer without loading unnecessary drivers and devices. This is commonly known as a "clean" or "vanilla" boot and can be very helpful for general troubleshooting computers running MS-DOS 6.0 (or higher): Press the F8 function key on your keyboard when the line "Starting MS-DOS" appears at startup time. This allows you to boot the CONFIG.SYS and AUTOEXEC.BAT line by line. You want to specify "yes" for loading the Device=C\DOS\HIMEM.SYS, and not anything else.


    For computers running older versions of MS-DOS, you can use a boot disk to get the same effect as the vanilla boot. To create a boot disk, you need a floppy that fits in your A:
    drive. Format the disk by typing the following at the DOS prompt:

    FORMAT A: /S

    [This is the command for high density drives. For low density and 5 1/4" drives, please consult your MS-DOS documentation. -Ed.]

    Once the format is complete, use the MS-DOS Editor to create a file on the disk called CONFIG.SYS. This is the same file that you used earlier to load devices. This time, however, the file needs to "tell" your system to load only one device, HIMEM, which is necessary to launch Windows. In this new file, then, you need only type one line:

    DEVICE=C:\DOS\HIMEM.SYS
    Make sure the file is saved to the floppy disk. Now, any time you want to see if doing a vanilla boot fixes your problem, insert the boot disk in your A: drive and reboot the
    computer.

    A few notes on troubleshooting memory issues
    Troubleshooting your Claris Windows applications may require that you make note of your computer's behavior. For example, you may be dealing with a memory issue if a problem or error occurs only when there is more than one file open. As another example, you may experience errors only during a certain sequence of events (e.g., you may change a style, then get a GPF or lock-up when attempting to print). Before treating these errors as memory-related, first ask yourself if you can rule out hardware errors: check cable connections; turn things on and off; reboot; check to see if the error occurs with other machines. If the error still occurs, check to see if the error occurs with other files. You could be dealing with damage in a single document, in which case you may need to resort to a backup. If the error still occurs in other documents, try the vanilla boot. Then, you can back up your CONFIG.SYS and AUTOEXEC.BAT files and try some of the simple editing techniques described in this article.


    Memory management tools and limited space
    Having zeroed in on your memory-related errors and found out that all of your conventional and upper memory has been used, you may consider investing in a third party expanded memory manager, such as QEMM or 386Max, utilities dedicated to handling memory on your PC. These utilities increase the capacity of the upper memory block, allowing you to load as many devices high as you need and freeing conventional memory for your programs.

    Please note: Mention of third party products constitutes neither an endorsement nor a recommendation. Claris assumes no responsibility with regard to the performance or use of third party products.


Document Information
Product Area: Apple Software
Category: Claris Software
Sub Category: General Topics

Copyright © 2000 Apple Computer, Inc. All rights reserved.