get_used_memory
Lawrence D’Oliveiro <[email protected]> Fri, 12 Jun 2026 03:46:43 -0000 (UTC)
| Newsgroups | comp.lang.python |
|---|---|
| Organization | A noiseless patient Spider |
| Message-ID | <[email protected]> |
So I looked at the example Gambas program at
<https://gambaswiki.org/wiki/doc/whatisgambas> and marvelled at its
unnecessary complexity (UUOC, even). It’s like PHP with variable
declarations!
Here’s my version: excluding header comments and blank lines and
shebang line, it’s about half the size.
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"]))