home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c005 / 4.ddi / C / MMSHRINK.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-04-13  |  2.0 KB  |  67 lines

  1. /**
  2. *
  3. * Name        mmshrink -- Release all memory not needed but allocated
  4. *                by DOS when the program is loaded.
  5. *        (Formerly called PCSHRINK.)
  6. *
  7. * Synopsis    ercode = mmshrink(psize);
  8. *
  9. *        int ercode      Return code from DOS function call
  10. *        unsigned *psize   Memory size of the program in paragraphs
  11. *                  after unused memory is released.
  12. *
  13. * Description    When DOS loads a program, all available memory is
  14. *        allocated to it.  MMSHRINK releases the memory beyond
  15. *        the program memory returning it to the free memory pool.
  16. *
  17. *        For large data memory models (or small machines), there
  18. *        may be no available memory if the stack and heap use all
  19. *        available memory.
  20. *
  21. * Method    The memory block is altered by making a call to
  22. *        MMSETBLK; the segment address of the block is given by
  23. *        the program segment prefix.
  24. *
  25. *        To compute the program size, we inspect the memory
  26. *        control block located 16 bytes before the program
  27. *        segment prefix.  The unsigned value located at offset 3
  28. *        in the control block is the size of the memory block
  29. *        containing the program.
  30. *
  31. * Returns    ercode          Error code returned from the call to
  32. *                  MMSETBLK.
  33. *        psize          Size of the memory block allocated to
  34. *                  program in paragraphs.
  35. *
  36. * Version    3.0  (C)Copyright Blaise Computing Inc.  1983, 1984, 1986
  37. *
  38. * Version    3.02 March 20, 1987
  39. *        Rewritten to use memory control block information to
  40. *          obtain program size.
  41. *
  42. **/
  43.  
  44. #include <bmemory.h>
  45. #include <butility.h>
  46.  
  47. int mmshrink(psize)
  48. unsigned *psize;
  49. {
  50.     ADS memctrl_ads;
  51.     ADS size_ads;
  52.  
  53.     /* The Lattice version 3 and Microsoft version 3 and 4 compilers  */
  54.     /* discard excess memory during program startup, so we need not   */
  55.     /* shrink the program ourselves.                      */
  56.  
  57.     /* Fetch program size from offset 3 of memory control block.      */
  58.  
  59.     memctrl_ads.s = utpspseg - 1;
  60.     memctrl_ads.r = 3;
  61.  
  62.     utabsptr((char *) psize,&size_ads);
  63.     utslmove(&memctrl_ads,&size_ads,sizeof(*psize));
  64.  
  65.     return 0;
  66. }
  67.