home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 1.ddi / CLIBSRC1.ZIP / CORELEFT.CAS < prev    next >
Encoding:
Text File  |  1992-06-10  |  1.8 KB  |  70 lines

  1. /*---------------------------------------------------------------------------
  2.  * filename - coreleft.cas
  3.  *
  4.  * function(s)
  5.  *    coreleft   - returns a measure of unused memory
  6.  *--------------------------------------------------------------------------*/
  7.  
  8. /*
  9.  *      C/C++ Run Time Library - Version 5.0
  10.  *
  11.  *      Copyright (c) 1987, 1992 by Borland International
  12.  *      All Rights Reserved.
  13.  *
  14.  */
  15.  
  16.  
  17. #pragma inline
  18. #include <asmrules.h>
  19. #include <alloc.h>
  20.  
  21. /*--------------------------------------------------------------------------*
  22.  
  23. Name            coreleft - returns a measure of unused memory
  24.  
  25. Usage           in the small data models :
  26.                 unsigned coreleft(void);
  27.  
  28.                 in the large data models(except huge) :
  29.                 unsigned long coreleft(void);
  30.  
  31. Prototype in    alloc.h
  32.  
  33. Description     returns a measure of the unused memory.  It gives different
  34.                 values of measurement, depending on the memory model.
  35.  
  36. Return value    in the small data models:
  37.                 the amount of unused memory between the stack and
  38.                 the data segment, minus a buffer margin.
  39.  
  40.                 in the large data models:
  41.                 the amount of unused memory between the heap and
  42.                 the stack.
  43. *---------------------------------------------------------------------------*/
  44.  
  45.  
  46. #if (LDATA)
  47. #include <_fheap.h>
  48.  
  49. unsigned long coreleft(void)
  50. {
  51.     return(farcoreleft());
  52. }
  53. #else
  54. #include <_heap.h>
  55.  
  56. unsigned coreleft(void)
  57. {
  58. asm mov ax, sp
  59. asm sub ax, word ptr __brklvl
  60.  
  61. /* +32 allows for increased stack useage in malloc */
  62. asm     sub     ax, (MARGIN + 32)
  63. asm     jnc     room_left:
  64. asm     xor     ax, ax
  65. room_left:
  66. asm     and     al, 0f0h
  67.     return _AX;
  68. }
  69. #endif
  70.