Microsoft KB Archive/50714
PRB: Avoiding R6009 "Not Enough Space for Environment" Error
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++, versions 1.0, 1.5, 1.51, 1.52
In the Microsoft C and Visual C++ products listed above, the following error message may be generated:
R6009: Not Enough Space For Environment
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.
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
- 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.)
If there is no need for command-line arguments, _setargv() can be rewritten as follows:
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:
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 query words: 6.00 6.00a 6.00ax 7.00 8.00 8.00c 1.00 1.50
Keywords : kb16bitonly kbprb
Issue type : kbprb
Technology : kbVCsearch kbAudDeveloper kbCRT
Last Reviewed: May 8, 2001