|
|
FUNCTION GetUsedMemory(byref ErrorMsg$) '=returns the memory used by the current process 'returns -1 if an error is encountered 'the error message is stored in the submitted variable ErrorMsg$ = "" struct ProcessMemoryCounters, _ cb as ulong,_ PageFaultCount as ulong,_ PeakWorkingSetSize as ulong,_ WorkingSetSize as ulong,_ QuotaPeakPagedPoolUsage as ulong,_ QuotaPagedPoolUsage as ulong,_ QuotaPeakNonPagedPoolUsage as ulong,_ QuotaNonPagedPoolUsage as ulong,_ PagefileUsage as ulong,_ PeakPagefileUsage as ulong ProcessMemoryCounters.cb.struct = len(ProcessMemoryCounters.struct) open "psapi.dll" for dll as #psapi calldll #kernel32, "GetCurrentProcess",hProcess as ulong cb = len(ProcessMemoryCounters.struct) calldll #psapi, "GetProcessMemoryInfo",_ hProcess as ulong,_ ProcessMemoryCounters as struct,_ cb as ulong,_ result as long if result then GetUsedMemory = ProcessMemoryCounters.PagefileUsage.struct else call GetLastError ErrorMsg$ GetUsedMemory = -1 end if close #psapi UsedMemory = GetUsedMemory/1000000 'convert to MB if instr(version$,"LBB")<>1 then if UsedMemory>65 then notice "Memory nearly full: "+using("####",UsedMemory) end if END FUNCTION SUB GetLastError byref Message$ calldll #kernel32, "GetLastError", ErrorCode as ulong dwFlags = _FORMAT_MESSAGE_FROM_SYSTEM nSize = 1024 lpBuffer$ = space$(nSize); chr$(0) dwMessageID = ErrorCode calldll #kernel32, "FormatMessageA", _ dwFlags as ulong, _ lpSource as ulong, _ dwMessageID as ulong, _ dwLanguageID as ulong, _ lpBuffer$ as ptr, _ nSize as ulong, _ Arguments as ulong, _ result as ulong Message$ = left$(lpBuffer$, result) END SUB
|