home *** CD-ROM | disk | FTP | other *** search
/ Groovy Bytes: Behind the Moon / groovybytes.iso / GROOVY / SND_TOOL / FUNK108A.ZIP / DOS32V30.ZIP / PAL / MALLOC / MEMAVAIL.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-05-20  |  1.8 KB  |  48 lines

  1. ;****************************************************************************
  2. ; Filename: MEMAVAIL.ASM
  3. ;   Author: Peter Andersson
  4. ;  Version: 0.0
  5. ;  Created: 1994.12.25
  6. ;  Updated: -
  7. ;****************************************************************************
  8. ; Copyright Peter Andersson, 1994-1995.
  9. ; All rights reserved.
  10. ;****************************************************************************
  11. ; Function: ULONG memavail(VOID);
  12. ;    Input: nothing
  13. ;   Output: total free memory available
  14. ;  Comment: PALmemavail returns the total amount of free memory in bytes on the
  15. ;           heap. The free memory size might be a bit smaller than expected as
  16. ;           each allocation adds some overhead. Observe: This function checks
  17. ;           ONLY available memory from what you have added with PALaddalloc and
  18. ;           PALaddmem. This has nothing to do with how much memory your system
  19. ;           has available.
  20. ;****************************************************************************
  21.  
  22.     Include    STDDEF.INC
  23.     Include    "MEMORY.INC"
  24.  
  25.     Codeseg
  26.  
  27. Proc    memavail
  28.         Mov    Edx,Offset BlockTable                    ; Get pointer to the free pointer list
  29.         Clear    Eax                            ; Clear the total amount of memory variable
  30.         Push    Ebx
  31.     Align    4
  32. @@Loop01:    Mov    Ebx,[Edx+FreeBlock.NextFree]                ; Get the first available FreeBlock
  33.     Align    4
  34. @@Loop02:    Mov    Ecx,[Ebx+FreeBlock.BlockSize]                ; Get the FreeBlock's block size
  35.         Jecxz    @@Next01                        ; If it's zero then exit
  36.         Lea    Eax,[Eax+Ecx-Size AllocBlock]                ; Add the block size
  37.         Mov    Ebx,[Ebx+FreeBlock.NextFree]                ; Move to the next FreeBlock
  38.         Jmp    @@Loop02
  39.     Align    4
  40. @@Next01:    Add    Edx,Size FreeBlock                    ; Go to the next free pointer list
  41.         Cmp    Edx,Offset BlockTableEnd                ; Do another lap if it hasn't reached the end
  42.         Jb    @@Loop01
  43.         Pop    Ebx
  44.         Ret                                ; Return with total amount of free memory
  45. Endp
  46.  
  47.     End
  48.