KCoreAddons

kmemoryinfo.h
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
15class KMemoryInfoPrivate;
16
17/**
18 * @brief The KMemoryInfo class provides an interface to get memory information (RAM/SWAP).
19 *
20 * To use the class, simply create an instance.
21 * \code
22 * KMemoryInfo memInfo;
23 * if (!memInfo.isNull()) {
24 * ...
25 * }
26 * \endcode
27 *
28 * @since 5.95
29 */
30class KCOREADDONS_EXPORT KMemoryInfo
31{
32public:
34
35 /**
36 * @brief KMemoryInfo
37 * Constructs a class with a snapshot of the state of the memory. If an error occurs, a null object is returned.
38 * @sa isNull.
39 */
41
42 /**
43 * @brief KMemoryInfo
44 * Constructs a copy of the other memoryinfo.
45 */
46 KMemoryInfo(const KMemoryInfo &other);
47
48 /**
49 * @brief operator =
50 * Makes a copy of the other memoryinfo and returns a reference to the copy.
51 */
52 KMemoryInfo &operator=(const KMemoryInfo &other);
53
54 /**
55 * @brief operator ==
56 * @return @c true if this memoryinfo is equal to the other memoryinfo, otherwise @c false.
57 */
58 bool operator==(const KMemoryInfo &other) const;
59
60 /**
61 * @brief operator !=
62 * @return @c true if this memoryinfo is different from the other memoryinfo, otherwise @c false.
63 */
64 bool operator!=(const KMemoryInfo &other) const;
65
66 /**
67 * @brief isNull
68 * @return @c true if the class is null, otherwise @c false.
69 */
70 bool isNull() const;
71
72 /**
73 * @brief totalPhysical
74 * @return The total system RAM in bytes.
75 */
76 quint64 totalPhysical() const;
77
78 /**
79 * @brief freePhysical
80 *
81 * The free memory is the amount of free RAM as reported by the operating system.
82 * This value is often tainted with caches and buffers used by the operating system, resulting in a low value.
83 * @note Don't use this value to determine if you have enough RAM for your data.
84 * @return The free RAM reported by OS in bytes.
85 * @sa availablePhysical.
86 */
87 quint64 freePhysical() const;
88
89 /**
90 * @brief availablePhysical
91 *
92 * The available memory is the free RAM without considering caches and buffers allocated by the operating system.
93 * @note You should always use this value to check if there is enough RAM for your data.
94 * @return The memory available to the processes in bytes.
95 * @sa freePhysical.
96 */
97 quint64 availablePhysical() const;
98
99 /**
100 * @brief cached
101 * @return The size of RAM used as cache in bytes.
102 */
103 quint64 cached() const;
104
105 /**
106 * @brief buffers
107 * @return The size of RAM used as buffers in bytes. This value can be zero.
108 */
109 quint64 buffers() const;
110
111 /**
112 * @brief totalSwapFile
113 * @return The size of swap file in bytes.
114 * @note On an operating system where the paging file is dynamically allocated, this value can be zero when no memory pages are swapped.
115 */
116 quint64 totalSwapFile() const;
117
118 /**
119 * @brief freeSwapFile
120 * @return The free swap size in bytes.
121 */
122 quint64 freeSwapFile() const;
123
124private:
125 /**
126 * @brief update Refresh the memory information.
127 * @return @c true on success, otherwise @c false.
128 */
129 KCOREADDONS_NO_EXPORT bool update();
130
132};
133
134#endif // KMEMORYINFO_H
The KMemoryInfo class provides an interface to get memory information (RAM/SWAP).
Definition kmemoryinfo.h:31
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 14 2024 11:58:27 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.