Microsoft KB Archive/48793

From BetaArchive Wiki
Knowledge Base

Article ID: 48793

Article Last Modified on 12/11/2003


  • The C Run-Time (CRT), when used with:
    • Microsoft C Professional Development System 5.1
    • Microsoft C Professional Development System 6.0
    • Microsoft C Professional Development System 6.0a
    • Microsoft C Professional Development System 6.0a
    • Microsoft C/C++ Professional Development System 7.0
    • Microsoft Visual C++ 1.0 Professional Edition
    • Microsoft Visual C++ 1.5 Professional Edition

This article was previously published under Q48793


The Microsoft C Run-time functions exec() and spawn() with P_OVERLAY ignore the maximum memory allocation information in the .EXE file header. If you exec or spawn with P_OVERLAY, a program whose maximum allocation is set equal to the minimum allocation (through EXEMOD or the LINK option /CP:1), the program is allocated the full 64K DGROUP.


The effective maximum allocation for any exec'ed (or spawn'ed with P_OVERLAY) program is 0xffff (whatever MS-DOS has available), regardless of the maximum allocation number in the program's .EXE header. When run from the MS-DOS prompt, the maximum allocation information of the same program is honored.

This behavior occurs because the exec() and spawn() functions with P_OVERLAY do not invoke COMMAND.COM, which looks at the minalloc and maxalloc fields in the .EXE file header. This is expected behavior for exec() and spawn() with P_OVERLAY. This is documented in the C run-time reference documentation for the exec() functions.


Instead of calling a program with exec() or spawn() with P_OVERLAY, call COMMAND.COM with the desired child program as an argument using exec() or spawn() with P_OVERLAY, as follows:


COMMAND.COM then loads your application as if it was from the MS-DOS prompt. Note, however, that the COMMAND.COM shell itself requires approximately 4K. Also, consecutive exec() or spawn() with P_OVERLAY calls using this method run additional shells of COMMAND.COM, accumulating one 4K shell per generation, as illustrated below:

          +------+    +------+    +------+    +------+
          |  P1  |--> |__P2__|--> |__P3__|--> |__P4__|
          +------+    | .COM |    |_.COM_|    |_.COM_|
                      +------+    | .COM |    |_.COM_|
                                  +------+    | .COM |

Another option is to call your program with the system() function, but this does not overlay the child process.

Additional query words: 1.00 1.50 6.00 6.00a 6.00ax 7.00 kbinf execl execle execlp execlpe execcv execve execvp execvpe spawnl spawnle spawnlp spawnlpe spawnv spawnve spawnvp spawnvpe

Keywords: kb16bitonly KB48793