@@ -23,6 +23,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
#pragma once
24
24
25
25
#include < cppcore/CPPCoreCommon.h>
26
+ #include < string.h>
27
+ #include < cinttypes>
26
28
27
29
namespace cppcore {
28
30
@@ -42,15 +44,27 @@ inline size_t align(size_t n) {
42
44
class DLL_CPPCORE_EXPORT MemUtils {
43
45
public:
44
46
// / @brief Will clear the given buffer with zero.
45
- // / @param buffer [inout] The buffer to clear.
47
+ // / @param[inout] buffer The buffer to clear.
46
48
static void clearMemory (void *buffer, size_t size);
47
49
50
+ // / @brief Will return true, if the pointer fits into the alignment.
51
+ // / @param[in] ptr The pointer to check.
52
+ // / @param[in] align The alignment to check for.
53
+ // / @return true if aligned, false if not.
48
54
static bool isAligned (const void *ptr, size_t align);
49
55
56
+ // / @brief Will align the given pointer.
57
+ // / @param[in] ptr The pointer to align.
58
+ // / @param[in] extra Space for headers / meta information.
59
+ // / @param[in] align The alignment to check for.
60
+ // / @return The aligned pointer.
50
61
static const void *alignPtr (void *ptr, size_t extra, size_t align);
51
62
52
- MemUtils () = delete ;
53
- ~MemUtils () = delete ;
63
+ // / @brief The default class constructor.
64
+ MemUtils () = default ;
65
+
66
+ // / @brief The class destructor.
67
+ ~MemUtils () = default ;
54
68
};
55
69
56
70
inline bool MemUtils::isAligned (const void *ptr, size_t align) {
@@ -64,6 +78,9 @@ inline bool MemUtils::isAligned(const void *ptr, size_t align) {
64
78
}
65
79
66
80
inline const void *MemUtils::alignPtr (void *ptr, size_t extra, size_t align) {
81
+ if (align == 0 ) {
82
+ return nullptr ;
83
+ }
67
84
union {
68
85
const void *mPtr ;
69
86
uintptr_t mAddr ;
0 commit comments