How to Find the Load Size Required for a Program

Last reviewed: July 17, 1997
Article ID: Q59768
6.00 6.00a 6.00ax 7.00 | 1.00 1.50
MS-DOS                 | WINDOWS
kbprg

The information in this article applies to:

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

SUMMARY

The final allocated segment within a program is stored in the second word of its program segment prefix (PSP). To find the size of the program in paragraphs, subtract the actual segment of the PSP from this segment number. This is useful in a number of applications, and can be used to find the amount of memory necessary to store a TSR (terminate-and-stay-resident) program.

MORE INFORMATION

In Microsoft C, the segment of the PSP is stored in the global variable _psp. This makes program load size easily accessible within C programs as demonstrated below. For more information on the PSP, see the "MS-DOS Encyclopedia," pages 108-111.

NOTE: The "MS_DOS Encyclopedia" is no longer being published. However, there are other third party reference books available that discuss the PSP.

Sample Code

#include<dos.h>

extern unsigned _psp;       /* segment of PSP                */
unsigned size;              /* size of program in paragraphs */
unsigned far *psp_pointer;  /* pointer to beginning of PSP   */

         /* psp_pointer[1] will contain the final allocated  */
         /* segment of the program stored in the second word */
         /* of the program segment prefix.                   */

void main(void)
{
     FP_SEG(psp_pointer)=_psp;
     FP_OFF(psp_pointer)=0;

     size= psp_pointer[1]-_psp;
}

NOTE: _psp is also declared in STDLIB.H. You can include this header file rather explicitly declare _psp as shown above.


Additional reference words: kbinf 6.00 6.00a 6.00ax 7.00 1.00 1.50
KBCategory: kbprg
KBSubcategory: CLngIss
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.