Q59768: How to Find the Load Size Required for a Program
Article: Q59768
Product(s): See article
Version(s): 4.00 5.00 5.10
Operating System(s): MS-DOS
Keyword(s): ENDUSER | s_quickc s_quickasm | mspl13_c
Last Modified: 9-APR-1990
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
including finding the amount of memory neccessary to store a TSR
(terminate and stay) program.
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)
{
FPSEG(psp_pointer)=_psp;
FPOFF(psp_pointer)=0;
size=_psp_pointer[1]-_psp;
}
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.
Copyright Microsoft Corporation 1986-2002.