PRB: Avoiding R6009 "Not Enough Space for Environment" Error

Last reviewed: July 17, 1997
Article ID: Q50714
5.00 5.10 6.00 6.00a 6.00ax 7.00 | 1.00 1.50
MS-DOS                           | WINDOWS
kbprg kbfasttip kbprb

The information in this article applies to:

  • The C Run-time (CRT) included with:

        - Microsoft C for MS-DOS, versions 5.0, 5.1, 6.0, 6.0a, and 6.0ax
        - Microsoft C/C++ for MS-DOS, version 7.0
        - Microsoft Visual C++ for Windows, versions 1.0, 1.5, 1.51 and
          1.52
    

SYMPTOMS

In the Microsoft C and Visual C++ products listed above, the following error message may be generated:

   R6009: Not Enough Space For Environment

CAUSE

The "R6009: Not Enough Space For Environment" run-time error is caused when a program successfully loads into memory and then attempts to load a copy of the environment and the argument list into the near heap. If the near heap does not have enough room for one, the other, or both, R6009 is generated.

RESOLUTION

The following are four ways to work around the problem:

  • Lower the amount of environment space with the following statement in the CONFIG.SYS file. This assumes that environment space is being allocated.

          shell=command.com /p /e:xxxx
    

    -or-

  • When compiling, use the large memory model in conjunction with the /Gt switch to get some of the global data out of DGROUP, thus freeing up room for the environment and/or the argument list. (/Gt3 is a good place to start.)

    -or-

  • If there is no need for command-line arguments, _setargv() can be rewritten as follows:

          _setargv() {}
    

    -or-

  • If there is no need for a copy of the environment, and if the spawn() or exec() functionality is not needed, _setenvp() can be rewritten as follows:

          _setenvp() {}
    

MORE INFORMATION

In standard Microsoft C programs, the functions _setargv() and _setenvp() attempt to set up the argument vector and the environment vector, respectively. Both of these vectors are allocated in the near heap. If the program has a full or nearly full near heap, the vectors will not be set up, thereby giving the error.


Additional reference words: 6.00 6.00a 6.00ax 7.00 8.00 8.00c 1.00 1.50
KBCategory: kbprg kbfasttip kbprb
KBSubcategory: CRTIss
Keywords : kb16bitonly


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 17, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.