home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name mmshrink -- Release all memory not needed but allocated
- * by DOS when the program is loaded.
- * (Formerly called PCSHRINK.)
- *
- * Synopsis ercode = mmshrink(psize);
- *
- * int ercode Return code from DOS function call
- * unsigned *psize Memory size of the program in paragraphs
- * after unused memory is released.
- *
- * Description When DOS loads a program, all available memory is
- * allocated to it. MMSHRINK releases the memory beyond
- * the program memory returning it to the free memory pool.
- *
- * For large data memory models (or small machines), there
- * may be no available memory if the stack and heap use all
- * available memory.
- *
- * Method The memory block is altered by making a call to
- * MMSETBLK; the segment address of the block is given by
- * the program segment prefix.
- *
- * To compute the program size, we inspect the memory
- * control block located 16 bytes before the program
- * segment prefix. The unsigned value located at offset 3
- * in the control block is the size of the memory block
- * containing the program.
- *
- * Returns ercode Error code returned from the call to
- * MMSETBLK.
- * psize Size of the memory block allocated to
- * program in paragraphs.
- *
- * Version 3.0 (C)Copyright Blaise Computing Inc. 1983, 1984, 1986
- *
- * Version 3.02 March 20, 1987
- * Rewritten to use memory control block information to
- * obtain program size.
- *
- **/
-
- #include <bmemory.h>
- #include <butility.h>
-
- int mmshrink(psize)
- unsigned *psize;
- {
- ADS memctrl_ads;
- ADS size_ads;
-
- /* The Lattice version 3 and Microsoft version 3 and 4 compilers */
- /* discard excess memory during program startup, so we need not */
- /* shrink the program ourselves. */
-
- /* Fetch program size from offset 3 of memory control block. */
-
- memctrl_ads.s = utpspseg - 1;
- memctrl_ads.r = 3;
-
- utabsptr((char *) psize,&size_ads);
- utslmove(&memctrl_ads,&size_ads,sizeof(*psize));
-
- return 0;
- }