home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / alde_c / misc / lib / dlibssrc / memavail.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-10-02  |  746 b   |  35 lines

  1. #include <osbind.h>
  2. #include <stdio.h>
  3.  
  4. #define    MAXBLK        16
  5. #define    FREE        0x00
  6. #define    USED        0x80
  7.  
  8. extern    char    *_mblk[];        /* major memory blocks */
  9.  
  10. long memavail()
  11. /*
  12.  *    Return the size, in bytes, of the largest block of free memory
  13.  *    available for allocation.  Note that this value is a long.
  14.  */
  15. {
  16.     register int i;
  17.     register long n, tsiz = 0L, **p, *q;
  18.  
  19.     for(i=0; i<MAXBLK; ++i) {
  20.         if((p = _mblk[i]) == NULL)
  21.             continue;        /* skip unavailable heaps */
  22.         while(q = *p) {
  23.             n = *q;
  24.             if(n > tsiz)        /* largest block so far */
  25.                 tsiz = n;
  26.             p = q + 1;
  27.         }
  28.     }
  29.     if((n = Malloc(-1L)) < 1024)
  30.         return(tsiz);
  31.     n -= (1024L + 16L);
  32.     n &= ~0x1FFL;            /* system memory available */
  33.     return((n > tsiz) ? n : tsiz);
  34. }
  35.