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.
This commit is contained in:
parent
b8da62bf43
commit
9029f897da
@ -37,8 +37,23 @@ find_package_handle_standard_args(JeMalloc DEFAULT_MSG
|
|||||||
JEMALLOC_INCLUDE_DIR
|
JEMALLOC_INCLUDE_DIR
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Check if the JeMalloc library was compiled with the "je_" prefix.
|
||||||
|
include(CheckSymbolExists)
|
||||||
|
set(CMAKE_REQUIRED_INCLUDES ${JEMALLOC_INCLUDE_DIR})
|
||||||
|
set(CMAKE_REQUIRED_LIBRARIES ${JEMALLOC_LIBRARY})
|
||||||
|
check_symbol_exists("je_malloc" "jemalloc/jemalloc.h" _jemalloc_is_prefixed)
|
||||||
|
unset(CMAKE_REQUIRED_INCLUDES)
|
||||||
|
unset(CMAKE_REQUIRED_LIBRARIES)
|
||||||
|
|
||||||
|
if(_jemalloc_is_prefixed)
|
||||||
|
set(JEMALLOC_IS_PREFIXED TRUE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
unset(_jemalloc_is_prefixed)
|
||||||
|
|
||||||
mark_as_advanced(
|
mark_as_advanced(
|
||||||
JEMALLOC_ROOT_DIR
|
JEMALLOC_ROOT_DIR
|
||||||
JEMALLOC_LIBRARY
|
JEMALLOC_LIBRARY
|
||||||
JEMALLOC_INCLUDE_DIR
|
JEMALLOC_INCLUDE_DIR
|
||||||
|
JEMALLOC_IS_PREFIXED
|
||||||
)
|
)
|
||||||
|
@ -215,3 +215,9 @@ ENDIF ()
|
|||||||
|
|
||||||
ADD_LIBRARY (star_core OBJECT ${star_core_SOURCES} ${star_core_HEADERS})
|
ADD_LIBRARY (star_core OBJECT ${star_core_SOURCES} ${star_core_HEADERS})
|
||||||
TARGET_PRECOMPILE_HEADERS (star_core PUBLIC StarPch.hpp)
|
TARGET_PRECOMPILE_HEADERS (star_core PUBLIC StarPch.hpp)
|
||||||
|
|
||||||
|
IF(STAR_USE_JEMALLOC AND JEMALLOC_IS_PREFIXED)
|
||||||
|
SET_SOURCE_FILES_PROPERTIES(StarMemory.cpp PROPERTIES
|
||||||
|
COMPILE_DEFINITIONS STAR_JEMALLOC_IS_PREFIXED
|
||||||
|
)
|
||||||
|
ENDIF()
|
@ -7,6 +7,7 @@
|
|||||||
namespace Star {
|
namespace Star {
|
||||||
|
|
||||||
#ifdef STAR_USE_JEMALLOC
|
#ifdef STAR_USE_JEMALLOC
|
||||||
|
#ifdef STAR_JEMALLOC_IS_PREFIXED
|
||||||
void* malloc(size_t size) {
|
void* malloc(size_t size) {
|
||||||
return je_malloc(size);
|
return je_malloc(size);
|
||||||
}
|
}
|
||||||
@ -32,6 +33,24 @@ namespace Star {
|
|||||||
return ::realloc(ptr, size);
|
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) {
|
void free(void* ptr) {
|
||||||
return ::free(ptr);
|
return ::free(ptr);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user