From 9029f897da1052f5a16cac6dc1a3069d1f26a192 Mon Sep 17 00:00:00 2001 From: Kai Blaschke Date: Wed, 21 Feb 2024 18:08:56 +0100 Subject: Support prefixed and non-prefixed JeMalloc functions Note that linking a JeMalloc library without prefixed functions will replace all memory allocations, including any call to "new", not just the ones specifically called via Star::malloc etc. --- source/core/StarMemory.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'source/core/StarMemory.cpp') diff --git a/source/core/StarMemory.cpp b/source/core/StarMemory.cpp index 3855283..9e73eb6 100644 --- a/source/core/StarMemory.cpp +++ b/source/core/StarMemory.cpp @@ -7,6 +7,7 @@ namespace Star { #ifdef STAR_USE_JEMALLOC +#ifdef STAR_JEMALLOC_IS_PREFIXED void* malloc(size_t size) { return je_malloc(size); } @@ -32,6 +33,24 @@ namespace Star { return ::realloc(ptr, size); } + void free(void* ptr) { + ::free(ptr); + } + + void free(void* ptr, size_t size) { + if (ptr) + ::sdallocx(ptr, size, 0); + } +#endif +#else + void* malloc(size_t size) { + return ::malloc(size); + } + + void* realloc(void* ptr, size_t size) { + return ::realloc(ptr, size); + } + void free(void* ptr) { return ::free(ptr); } -- cgit v1.2.3