Changes to be made
From Méven Car:
Your code looks quite good. Thank you for the effort.
A few things, since you are not familiar we our standards:
- licensing, we have SPDX header format, you can see an example at https://invent.kde.org/frameworks/kcoreaddons/-/blob/master/src/lib/util/kprocesslist.h
- We use
/**
as beginning for documentation in doxygen comments blocks, and use@
as key prefix - Since it is a framework class we like to have some autotest for it.
- We will need to add a @since to the header of the class, probably @since 5.95
- we don't write this->, _ prefix should be enough for code comprehension
- Make the ctor private, the class should only be instantiated through the static current() method.
- In KDE Framework,
qDebug() << "KMemoryInfo: unsupported platform!";
would beqCWarning(MY_LOG) << "KMemoryInfo: unsupported platform!";
- try to remove the commented code or ask about it, if you can't be decisive.
You should always use this value to check if there is enough RAM for your data.
That is great and important comment. The tldr
Once you feel your code is mature enough, you can create a MR in https://invent.kde.org/frameworks/kcoreaddons and cc me I would suggest you to use the src/lib/util
folder. You will be able to use git clang-format
to conform with the KDE Frameworks code style automatically, (We use if () {
, return value;
...
You can harden your code, grabbing inspiration from ksysguard https://invent.kde.org/plasma/ksysguard/-/blob/master/ksysguardd/Linux/Memory.c you could also have a look at kinfocenter Modules/about-distro/src/MemoryEntry.cpp I identified some code in okular (https://invent.kde.org/graphics/okular/-/blob/master/core/document.cpp#L474) , kinfocenter (https://invent.kde.org/plasma/kinfocenter/-/blob/master/Modules/about-distro/src/MemoryEntry.cpp) and gwenview/lib/memoryutils.cpp that could use this class instead of doing it themselves. We should make sure the new API covers those apps needs, but maybe not ksysguard.
gwenview uses duplicated code from okular, it uses this as available memory:
// read /proc/meminfo and sum up the contents of 'MemFree', 'Buffers'
// and 'Cached' fields. consider swapped memory as used memory.