base:GetAvailableMemory()

You can post your code snippets here for others to use and learn from

base:GetAvailableMemory()

Postby djrikki » Wed Apr 15, 2015 11:31 pm

A very crude, but otherwise effective way of returning the amount of available memory.

Depends on my separate base:ConvertBytes() and base:DeleteFile() functions, see separate threads.

Code: Select all
Global base, application, locale, systempartition
base = {}
application = {}
locale = {}

application.name = "MyApp"
application.t = "T:"
application.platform = GetVersion().platform

If application.platform = "MorphOS"
    systempartition = "MOSSYS:"
Else
    systempartition = "SYS:"
EndIf

application.cfolder = systempartition .. "C/"

DimStr locale[1]
locale[663] = "Unknown"

;; base:GetAvailableMemory()
Function base:GetAvailableMemory()
    Local gotline$, memory$, bytename
   
    If application.platform = "AmigaOS4"
       Execute(application.cfolder .. "Avail show byte >" .. application.t .. application.name .. "_availmem")
   
       Wait(50)
      
          OpenFile(1,application.t .. application.name .. "_availmem")
          gotline$ = ReadLine(1)
          gotline$ = MidStr(gotline$,FindStr(gotline$,":")+2,StrLen(gotline$))
          CloseFile(1)
           
      gotline$ = ReplaceStr(gotline$,",","")
          gotline$ = ReplaceStr(gotline$,".","")
   
       gotline$, bytename = base:ConvertBytes(ToNumber(gotline$))
             
       If FindStr(gotline$,".") > -1
           gotline$ = MidStr(gotline$,0, FindStr(gotline$,".")) ; strip away any decimals
       EndIf
   
       base:DeleteFile(application.t .. application.name .. "_availmem")
       
    ElseIf application.platform = "AROS"
        Execute(application.cfolder .. "Avail total >" .. application.t .. application.name .. "_availmem")
        Wait(50)
          OpenFile(1,application.t .. appplication.name .. "_availmem")
          gotline$ = ReadLine(1)
          CloseFile(1)
          gotline$, bytename = base:ConvertBytes(ToNumber(gotline$))
          
          base:DeleteFile(application.t .. application.name .. "_availmem")
          
    Else
       
        gotline$ = locale[663]
        bytename = ""
    EndIf
   
    Return(gotline$, bytename) 
EndFunction
Evolve - Rapid GUI Development tool for MUI Royale and RapaGUI
http://myevolve.wordpress.com
djrikki
 
Posts: 645
Joined: Wed Apr 06, 2011 12:26 am

Return to Code snippets area

Who is online

Users browsing this forum: No registered users and 1 guest

cron