aboutsummaryrefslogtreecommitdiff
path: root/src/zencore/memory.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2023-12-12 13:07:09 +0100
committerGitHub <[email protected]>2023-12-12 13:07:09 +0100
commit11f388977f9b1eeaa7c00c7962b82c996a912904 (patch)
tree45a8652272dd66e4f53bf32348e1dcc5cb13c130 /src/zencore/memory.cpp
parentAdding an info command to display a top-level summary of disk space etc (#602) (diff)
downloadzen-11f388977f9b1eeaa7c00c7962b82c996a912904.tar.xz
zen-11f388977f9b1eeaa7c00c7962b82c996a912904.zip
use mimalloc where available (#601)
enabling mimalloc path for `Memory::Alloc` and `Memory::Free`
Diffstat (limited to 'src/zencore/memory.cpp')
-rw-r--r--src/zencore/memory.cpp26
1 files changed, 11 insertions, 15 deletions
diff --git a/src/zencore/memory.cpp b/src/zencore/memory.cpp
index 546296b10..808c9fcb6 100644
--- a/src/zencore/memory.cpp
+++ b/src/zencore/memory.cpp
@@ -7,13 +7,12 @@
#include <zencore/testing.h>
#include <zencore/zencore.h>
-#if ZEN_PLATFORM_WINDOWS
-# include <malloc.h>
+#include <cstdlib>
+
+#if ZEN_USE_MIMALLOC
ZEN_THIRD_PARTY_INCLUDES_START
# include <mimalloc.h>
ZEN_THIRD_PARTY_INCLUDES_END
-#else
-# include <cstdlib>
#endif
namespace zen {
@@ -23,16 +22,15 @@ namespace zen {
static void*
AlignedAllocImpl(size_t Size, size_t Alignment)
{
-#if ZEN_PLATFORM_WINDOWS
-# if ZEN_USE_MIMALLOC && 0 /* this path is not functional */
- return mi_aligned_alloc(Alignment, Size);
-# else
- return _aligned_malloc(Size, Alignment);
-# endif
-#else
// aligned_alloc() states that size must be a multiple of alignment. Some
// platforms return null if this requirement isn't met.
Size = (Size + Alignment - 1) & ~(Alignment - 1);
+
+#if ZEN_USE_MIMALLOC
+ return mi_aligned_alloc(Alignment, Size);
+#elif ZEN_PLATFORM_WINDOWS
+ return _aligned_malloc(Size, Alignment);
+#else
return std::aligned_alloc(Alignment, Size);
#endif
}
@@ -43,12 +41,10 @@ AlignedFreeImpl(void* ptr)
if (ptr == nullptr)
return;
-#if ZEN_PLATFORM_WINDOWS
-# if ZEN_USE_MIMALLOC && 0 /* this path is not functional */
+#if ZEN_USE_MIMALLOC
return mi_free(ptr);
-# else
+#elif ZEN_PLATFORM_WINDOWS
_aligned_free(ptr);
-# endif
#else
std::free(ptr);
#endif