PRB: R6009: "Not Enough Space for Environment" When Heap Full

ID: Q63382


The information in this article applies to:
  • Microsoft FORTRAN for MS-DOS, versions 4.0, 4.01, 4.1, 5.0, 5.1
  • Microsoft FORTRAN for OS/2, versions 4.1, 5.0, 5.1


SYMPTOMS

An attempt to run an application fails and the following message appears on the screen:

R6009: Not Enough Space For Environment


CAUSE

After the application loads into memory, this error occurs when the application is unable to load a copy of the environment and the argument list into the near heap.


RESOLUTION

To work around this problem, perform one of the following four steps:

  • If the CONFIG.SYS file contains a SHELL statement with the /e: parameter, reduce the amount of environment space SHELL allocates by reducing the value specified in the /e: parameter. The SHELL statement should somewhat resemble the following:
    
          shell=c:\command.com /p /e:xxxx 


  • -or-

  • Compile the application with the large memory model. Specify the /Gt compiler option switch to remove some global data from the DGROUP default data segment and free memory for the environment and the argument list. (The /Gt0 compiler option switch removes the most data from DGROUP.)


  • -or-

  • If the application does not use any command-line arguments, rewrite the C function _setargv() to do nothing. If the application does not need a copy of its environment, rewrite the C function _setenvp(). The code example below demonstrates eliminating these two C functions in FORTRAN.


  • -or-

  • Reduce the stack size to provide room for the command-line arguments and the environment.



MORE INFORMATION

In an application developed in standard Microsoft C, the _setargv() and _setenvp() functions attempt to set up the argument vector and the environment vector, respectively. Each of these vectors is allocated from the near heap. In the near heap is full, or nearly full, the functions are unable to set up the vectors and the R6009 run-time error occurs.

To prevent the error, substitute a null function for the _setargv() and _setenvp() functions to prevent the near heap allocation from taking place. The following FORTRAN code example performs this task. Specify the /NOE linker option switch to prevent the "L2044: symbol multiply defined" error.

Sample Code


C Compile options needed: None

      INTERFACE TO SUBROUTINE SETARGV[C, ALIAS:'__setargv']()
      END
      INTERFACE TO SUBROUTINE SETENVP[C, ALIAS:'__setenvp']()
      END
      SUBROUTINE SETARGV
      RETURN
      END
      SUBROUTINE SETENVP
      RETURN
      END 

Additional query words: 4.00 4.01 4.10 5.00 5.10

Keywords :
Version : :4.0,4.01,4.1,5.0,5.1
Platform :
Issue type :


Last Reviewed: November 1, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.