INF: How to Find the Load Size Required for a Program

ID Number: Q59768

4.00 5.00 5.10 6.00 6.00a 6.00ax 7.00

MS-DOS

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.

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;

}

Additional reference words: 4.00 5.00 5.10 2.00 2.01 5.10 6.00 6.00a

6.00ax 7.00