From 3fbc2045a49cd476e66c53676effe48e29bab0d8 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 16 Jul 2024 21:04:11 +0200 Subject: [PATCH 1/2] Enable linkage --- include/cppcore/Memory/MemUtils.h | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/include/cppcore/Memory/MemUtils.h b/include/cppcore/Memory/MemUtils.h index e0b57a7..598bfc7 100644 --- a/include/cppcore/Memory/MemUtils.h +++ b/include/cppcore/Memory/MemUtils.h @@ -22,6 +22,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -----------------------------------------------------------------------------------------------*/ #pragma once +#include #include #include @@ -40,18 +41,30 @@ inline size_t align(size_t n) { /// /// @brief Utility class for common memory operations. //------------------------------------------------------------------------------------------------- -class MemUtils { +class DLL_CPPCORE_EXPORT MemUtils { public: /// @brief Will clear the given buffer with zero. - /// @param buffer [inout] The buffer to clear. + /// @param[inout] buffer The buffer to clear. static void clearMemory(void *buffer, size_t size); + /// @brief Will return true, if the pointer fits into the alignment. + /// @param[in] ptr The pointer to check. + /// @param[in] align The alignment to check for. + /// @return true if aligned, false if not. static bool isAligned(const void *ptr, size_t align); + /// @brief Will align the given pointer. + /// @param[in] ptr The pointer to align. + /// @param[in] extra Space for headers / meta information. + /// @param[in] align The alignment to check for. + /// @return The aligned pointer. static const void *alignPtr(void *ptr, size_t extra, size_t align); - MemUtils() = delete; - ~MemUtils() = delete; + /// @brief The default class constructor. + MemUtils() = default; + + /// @brief The class destructor. + ~MemUtils() = default; }; inline bool MemUtils::isAligned(const void *ptr, size_t align) { From ecdb2f6c7a50d3baa00b335c55c1d574021da4c2 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 16 Jul 2024 21:12:29 +0200 Subject: [PATCH 2/2] Update MemUtils.h Fix review finding --- include/cppcore/Memory/MemUtils.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/cppcore/Memory/MemUtils.h b/include/cppcore/Memory/MemUtils.h index 598bfc7..64fbf6f 100644 --- a/include/cppcore/Memory/MemUtils.h +++ b/include/cppcore/Memory/MemUtils.h @@ -22,7 +22,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -----------------------------------------------------------------------------------------------*/ #pragma once -#include +#include #include #include @@ -78,6 +78,9 @@ inline bool MemUtils::isAligned(const void *ptr, size_t align) { } inline const void *MemUtils::alignPtr(void *ptr, size_t extra, size_t align) { + if (align == 0) { + return nullptr; + } union { const void *mPtr; uintptr_t mAddr;