From Newsgroup: comp.lang.misc
Having a look at the intro to Gambas <
https://gambaswiki.org/wiki/doc/whatisgambas> out of curiosity, and
found this example program:
Function GetUsedMemory() AS Long
Dim sRes As String
Dim aRes As String[]
Dim cVal As New Collection
Dim sVal As String
Exec ["cat", "/proc/meminfo"] To sRes
For Each sVal In Split(sRes, "\n", "", True)
aRes = Split(sVal, " ", "", True)
cVal[Left$(aRes[0], -1)] = CLong(aRes[1])
Next
Return cVal!MemTotal - cVal!MemFree - cVal!Buffers - cVal!Cached + cVal!SwapTotal - cVal!SwapFree - cVal!SwapCached
End
Print Subst("Used memory: &1 Kb", GetUsedMemory())
Even without the UUOC, it’s still pretty long-winded. Here’s my Python version:
info = dict \
(
(entry[0][:-1], int(entry[-2]))
for line in open("/proc/meminfo", "rt")
for entry in (tuple(s.strip() for s in line.split(" ")),)
if entry[-2] != ""
)
print("Used memory: %d Kb" % (info["MemTotal"] - info["MemFree"] - info["Buffers"] - info["Cached"] + info["SwapTotal"] - info["SwapFree"] - info["SwapCached"]))
--- Synchronet 3.21a-Linux NewsLink 1.2