| 1 | /* |
| 2 | This file is part of the KDE Frameworks |
| 3 | |
| 4 | SPDX-FileCopyrightText: 2022 Mirco Miranda |
| 5 | |
| 6 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 7 | */ |
| 8 | #ifndef KMEMORYINFO_H |
| 9 | #define KMEMORYINFO_H |
| 10 | |
| 11 | #include <QSharedDataPointer> |
| 12 | |
| 13 | #include <kcoreaddons_export.h> |
| 14 | |
| 15 | class KMemoryInfoPrivate; |
| 16 | |
| 17 | /*! |
| 18 | * \class KMemoryInfo |
| 19 | * \inmodule KCoreAddons |
| 20 | * |
| 21 | * \brief The KMemoryInfo class provides an interface to get memory information (RAM/SWAP). |
| 22 | * |
| 23 | * To use the class, simply create an instance. |
| 24 | * \code |
| 25 | * KMemoryInfo memInfo; |
| 26 | * if (!memInfo.isNull()) { |
| 27 | * ... |
| 28 | * } |
| 29 | * \endcode |
| 30 | * |
| 31 | * \since 5.95 |
| 32 | */ |
| 33 | class KCOREADDONS_EXPORT KMemoryInfo |
| 34 | { |
| 35 | public: |
| 36 | ~KMemoryInfo(); |
| 37 | |
| 38 | /*! |
| 39 | * Constructs a class with a snapshot of the state of the memory. If an error occurs, a null object is returned. |
| 40 | * \sa isNull. |
| 41 | */ |
| 42 | KMemoryInfo(); |
| 43 | |
| 44 | KMemoryInfo(const KMemoryInfo &other); |
| 45 | |
| 46 | KMemoryInfo &operator=(const KMemoryInfo &other); |
| 47 | |
| 48 | /*! |
| 49 | * Returns \c true if this memoryinfo is equal to the other memoryinfo, otherwise \c false. |
| 50 | */ |
| 51 | bool operator==(const KMemoryInfo &other) const; |
| 52 | |
| 53 | /*! |
| 54 | * Returns \c true if this memoryinfo is different from the other memoryinfo, otherwise \c false. |
| 55 | */ |
| 56 | bool operator!=(const KMemoryInfo &other) const; |
| 57 | |
| 58 | /*! |
| 59 | * Returns \c true if the class is null, otherwise \c false. |
| 60 | */ |
| 61 | bool isNull() const; |
| 62 | |
| 63 | /*! |
| 64 | * Returns The total system RAM in bytes. |
| 65 | */ |
| 66 | quint64 totalPhysical() const; |
| 67 | |
| 68 | /*! |
| 69 | * The free memory is the amount of free RAM as reported by the operating system. |
| 70 | * This value is often tainted with caches and buffers used by the operating system, resulting in a low value. |
| 71 | * |
| 72 | * \note Don't use this value to determine if you have enough RAM for your data. |
| 73 | * |
| 74 | * Returns the free RAM reported by OS in bytes. |
| 75 | * \sa availablePhysical. |
| 76 | */ |
| 77 | quint64 freePhysical() const; |
| 78 | |
| 79 | /*! |
| 80 | * The available memory is the free RAM without considering caches and buffers allocated by the operating system. |
| 81 | * |
| 82 | * \note You should always use this value to check if there is enough RAM for your data. |
| 83 | * |
| 84 | * Returns The memory available to the processes in bytes. |
| 85 | * \sa freePhysical. |
| 86 | */ |
| 87 | quint64 availablePhysical() const; |
| 88 | |
| 89 | /*! |
| 90 | * Returns The size of RAM used as cache in bytes. |
| 91 | */ |
| 92 | quint64 cached() const; |
| 93 | |
| 94 | /*! |
| 95 | * Returns The size of RAM used as buffers in bytes. This value can be zero. |
| 96 | */ |
| 97 | quint64 buffers() const; |
| 98 | |
| 99 | /*! |
| 100 | * Returns The size of swap file in bytes. |
| 101 | * |
| 102 | * \note On an operating system where the paging file is dynamically allocated, this value can be zero when no memory pages are swapped. |
| 103 | */ |
| 104 | quint64 totalSwapFile() const; |
| 105 | |
| 106 | /*! |
| 107 | * Returns The free swap size in bytes. |
| 108 | */ |
| 109 | quint64 freeSwapFile() const; |
| 110 | |
| 111 | private: |
| 112 | KCOREADDONS_NO_EXPORT bool update(); |
| 113 | |
| 114 | QSharedDataPointer<KMemoryInfoPrivate> d; |
| 115 | }; |
| 116 | |
| 117 | #endif // KMEMORYINFO_H |
| 118 | |