KMemoryInfo Class

The KMemoryInfo class provides an interface to get memory information (RAM/SWAP). More...

Header: #include <KMemoryInfo>
CMake: find_package(KF6 REQUIRED COMPONENTS CoreAddons)
target_link_libraries(mytarget PRIVATE KF6::CoreAddons)
Since: 5.95

Public Functions

KMemoryInfo()
quint64 availablePhysical() const
quint64 buffers() const
quint64 cached() const
quint64 freePhysical() const
quint64 freeSwapFile() const
bool isNull() const
quint64 totalPhysical() const
quint64 totalSwapFile() const
bool operator!=(const KMemoryInfo &other) const
bool operator==(const KMemoryInfo &other) const

Detailed Description

To use the class, simply create an instance.

KMemoryInfo memInfo;
if (!memInfo.isNull()) {
    ...
}

Member Function Documentation

KMemoryInfo::KMemoryInfo()

Constructs a class with a snapshot of the state of the memory. If an error occurs, a null object is returned.

See also isNull.

quint64 KMemoryInfo::availablePhysical() const

The available memory is the free RAM without considering caches and buffers allocated by the operating system.

Note: You should always use this value to check if there is enough RAM for your data. Returns The memory available to the processes in bytes.

See also freePhysical.

quint64 KMemoryInfo::buffers() const

Returns The size of RAM used as buffers in bytes. This value can be zero.

quint64 KMemoryInfo::cached() const

Returns The size of RAM used as cache in bytes.

quint64 KMemoryInfo::freePhysical() const

The free memory is the amount of free RAM as reported by the operating system. This value is often tainted with caches and buffers used by the operating system, resulting in a low value.

Note: Don't use this value to determine if you have enough RAM for your data. Returns the free RAM reported by OS in bytes.

See also availablePhysical.

quint64 KMemoryInfo::freeSwapFile() const

Returns The free swap size in bytes.

bool KMemoryInfo::isNull() const

Returns true if the class is null, otherwise false.

quint64 KMemoryInfo::totalPhysical() const

Returns The total system RAM in bytes.

quint64 KMemoryInfo::totalSwapFile() const

Returns The size of swap file in bytes.

Note: On an operating system where the paging file is dynamically allocated, this value can be zero when no memory pages are swapped.

bool KMemoryInfo::operator!=(const KMemoryInfo &other) const

Returns true if this memoryinfo is different from the other memoryinfo, otherwise false.

bool KMemoryInfo::operator==(const KMemoryInfo &other) const

Returns true if this memoryinfo is equal to the other memoryinfo, otherwise false.