Microsoft KB Archive/59768

{|
 * width="100%"|

How to Find the Load Size Required for a Program

 * }

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 &quot;MS-DOS Encyclopedia,&quot; pages 108-111. NOTE: The &quot;MS_DOS Encyclopedia&quot; is no longer being published. However, there are other third party reference books available that discuss the PSP. Sample Code --- #include 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

Issue type :

Technology : kbVCsearch kbAudDeveloper kbPTProdChange kbvc150 kbvc100 kbCCompSearch kbZNotKeyword3 kbCComp600DOS kbCComp600aDOS kbCComp600axDOS kbCVC700DOS