exec() and spawn() with P_OVERLAY Ignore Max AllocationLast reviewed: July 17, 1997Article ID: Q48793 |
5.10 6.00 6.00a 6.00ax 7.00 | 1.00 1.50
MS-DOS | WINDOWSkbprg The information in this article applies to:
SUMMARYThe 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.
MORE INFORMATIONThe 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.
AlternativesInstead 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:
spawnl(P_OVERLAY,"c:\\command.com","command.com", "/cchild.exe",NULL);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 reference words: 1.00 1.50 6.00 6.00a 6.00ax 7.00 kbinf execl
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |