diff --git a/CMakeLists.txt b/CMakeLists.txt index 1bacca1a48..5ef2cb161b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,6 +35,10 @@ macro (OCCT_INCLUDE_CMAKE_FILE BEING_INCLUDED_FILE) endif() endmacro() +# set using memory manager option for TKernel +set (USE_MMGR_TYPE "NATIVE" CACHE STRING "Select using memory manager tool.") +set_property(CACHE USE_MMGR_TYPE PROPERTY STRINGS "NATIVE" "FLEXIBLE" "TBB" "JEMALLOC") + # include variable description OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/vardescr") @@ -834,6 +838,14 @@ else() OCCT_CHECK_AND_UNSET ("3RDPARTY_FLEX_EXECUTABLE") endif() +# Jemalloc +if ("${USE_MMGR_TYPE}" STREQUAL "JEMALLOC") + OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/jemalloc") +else() + OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_JEMALLOC") + OCCT_CHECK_AND_UNSET ("INSTALL_JEMALLOC") +endif() + # qt for inspector and samples if (BUILD_Inspector OR BUILD_SAMPLES_QT) # check qt 3rdparty path diff --git a/adm/cmake/jemalloc.cmake b/adm/cmake/jemalloc.cmake new file mode 100644 index 0000000000..b37d5d2769 --- /dev/null +++ b/adm/cmake/jemalloc.cmake @@ -0,0 +1,143 @@ +# JeMalloc + +if (NOT DEFINED INSTALL_JEMALLOC) + set (INSTALL_JEMALLOC OFF CACHE BOOL "${INSTALL_INSTALL_JEMALLOC_DESCR}") +endif() + +# include occt macros. compiler_bitness, os_with_bit, compiler +OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/occt_macros") + +# specify JEMALLOC folder in connection with 3RDPARTY_DIR +if (3RDPARTY_DIR AND EXISTS "${3RDPARTY_DIR}") + if (NOT 3RDPARTY_JEMALLOC_DIR OR NOT EXISTS "${3RDPARTY_JEMALLOC_DIR}") + FIND_PRODUCT_DIR ("${3RDPARTY_DIR}" jemalloc JEMALLOC_DIR_NAME) + if (JEMALLOC_DIR_NAME) + set (3RDPARTY_JEMALLOC_DIR "${3RDPARTY_DIR}/${JEMALLOC_DIR_NAME}" CACHE PATH "The directory containing JEMALLOC" FORCE) + set (3RDPARTY_JEMALLOC_DIR "${3RDPARTY_DIR}/${JEMALLOC_DIR_NAME}") + message(STATUS "Info: JEMALLOC detected in ${3RDPARTY_JEMALLOC_DIR}") + endif() + endif() + else() +endif() + +# define required JEMALLOC variables +if (NOT DEFINED 3RDPARTY_JEMALLOC_INCLUDE_DIR) + set (3RDPARTY_JEMALLOC_INCLUDE_DIR "" CACHE PATH "the path of headers directory") +endif() + +# check 3RDPARTY_${PRODUCT_NAME}_ paths for consistency with specified 3RDPARTY_${PRODUCT_NAME}_DIR +if (3RDPARTY_JEMALLOC_DIR AND EXISTS "${3RDPARTY_JEMALLOC_DIR}") + CHECK_PATH_FOR_CONSISTENCY (3RDPARTY_JEMALLOC_DIR 3RDPARTY_JEMALLOC_INCLUDE_DIR PATH "the path to JEMALLOC") + CHECK_PATH_FOR_CONSISTENCY (3RDPARTY_JEMALLOC_DIR 3RDPARTY_JEMALLOC_LIBRARY_DIR FILEPATH "The directory containing JEMALLOC libraries") +endif() + +# header +if (NOT 3RDPARTY_JEMALLOC_INCLUDE_DIR OR NOT EXISTS "${3RDPARTY_JEMALLOC_INCLUDE_DIR}") + set (HEADER_NAMES jemalloc.h) + + # set 3RDPARTY_JEMALLOC_INCLUDE_DIR as notfound, otherwise find_library can't assign a new value to 3RDPARTY_JEMALLOC_INCLUDE_DIR + set (3RDPARTY_JEMALLOC_INCLUDE_DIR "3RDPARTY_JEMALLOC_INCLUDE_DIR-NOTFOUND" CACHE FILEPATH "the path to header directory" FORCE) + + if (3RDPARTY_JEMALLOC_DIR AND EXISTS "${3RDPARTY_JEMALLOC_DIR}") + find_path (3RDPARTY_JEMALLOC_INCLUDE_DIR NAMES ${HEADER_NAMES} + PATHS ${3RDPARTY_JEMALLOC_DIR} + PATH_SUFFIXES include/jemalloc + CMAKE_FIND_ROOT_PATH_BOTH + NO_DEFAULT_PATH) + endif() +endif() + +if (3RDPARTY_JEMALLOC_INCLUDE_DIR AND EXISTS "${3RDPARTY_JEMALLOC_INCLUDE_DIR}") + list (APPEND 3RDPARTY_INCLUDE_DIRS "${3RDPARTY_JEMALLOC_INCLUDE_DIR}") +else() + list (APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_JEMALLOC_INCLUDE_DIR) + set (3RDPARTY_JEMALLOC_INCLUDE_DIR "" CACHE FILEPATH "the path to jemalloc.h" FORCE) +endif() + +# Installing destination path +if (WIN32) + set (JEMALLOC_INSTALL_DESTINATION "${INSTALL_DIR}/${INSTALL_DIR_BIN}") +else() + set (JEMALLOC_INSTALL_DESTINATION "${INSTALL_DIR}/${INSTALL_DIR_LIB}") +endif() + +macro (JEMALLOC_LIB_SEARCH MMGR_LIB PREFIX) +if (NOT 3RDPARTY_JEMALLOC_LIBRARY_${PREFIX}_${MMGR_LIB}) + set (JEMALLOC_PATH_SUFFIXES "lib" "bin") + set (3RDPARTY_JEMALLOC_LIBRARY_${PREFIX}_${MMGR_LIB} "3RDPARTY_JEMALLOC_LIBRARY_${PREFIX}_${MMGR_LIB}-NOTFOUND") + if (3RDPARTY_JEMALLOC_DIR AND EXISTS "${3RDPARTY_JEMALLOC_DIR}") + find_library (3RDPARTY_JEMALLOC_LIBRARY_${PREFIX}_${MMGR_LIB} NAMES ${MMGR_LIB} + PATHS "${3RDPARTY_JEMALLOC_LIBRARY_DIR}" "${3RDPARTY_JEMALLOC_DIR}" + PATH_SUFFIXES ${JEMALLOC_PATH_SUFFIXES} + CMAKE_FIND_ROOT_PATH_BOTH + NO_DEFAULT_PATH) + else() + find_library (3RDPARTY_JEMALLOC_LIBRARY_${PREFIX}_${MMGR_LIB} NAMES ${MMGR_LIB} + PATH_SUFFIXES ${JEMALLOC_PATH_SUFFIXES} + CMAKE_FIND_ROOT_PATH_BOTH) + endif() + if (3RDPARTY_JEMALLOC_LIBRARY_${PREFIX}_${MMGR_LIB}) + get_filename_component (3RDPARTY_JEMALLOC_LIBRARY_DIR_${MMGR_LIB} "${3RDPARTY_JEMALLOC_LIBRARY_${PREFIX}_${MMGR_LIB}}" PATH) + set (3RDPARTY_JEMALLOC_LIBRARY_DIR_${MMGR_LIB} "${3RDPARTY_JEMALLOC_LIBRARY_DIR_${MMGR_LIB}}") + else() + set (3RDPARTY_JEMALLOC_LIBRARY_DIR_${MMGR_LIB} "") + endif() +endif() +if (3RDPARTY_JEMALLOC_LIBRARY_DIR_${MMGR_LIB}) + list (APPEND 3RDPARTY_LIBRARY_DIRS "${3RDPARTY_JEMALLOC_LIBRARY_DIR_${MMGR_LIB}}") + set (3RDPARTY_JEMALLOC_LIBRARY_DIR "${3RDPARTY_JEMALLOC_LIBRARY_DIR_${MMGR_LIB}}" CACHE PATH "The directory containing JEMALLOC libraries" FORCE) +else() + message("Cannot find ${MMGR_LIB} library in jemalloc 3rdparty") + list (APPEND 3RDPARTY_NO_LIBS 3RDPARTY_JEMALLOC_LIBRARY_DIR_${MMGR_LIB}) + set (3RDPARTY_JEMALLOC_LIBRARY_${PREFIX}_${MMGR_LIB} "") +endif() +set (JEMALLOC_IS_STATIC_LIB FALSE) +if (((${3RDPARTY_JEMALLOC_LIBRARY_${PREFIX}_${MMGR_LIB}} MATCHES "\.lib$")) OR ((${3RDPARTY_JEMALLOC_LIBRARY_${PREFIX}_${MMGR_LIB}} MATCHES "\.a$"))) + get_filename_component(STATIC_LIB_NAME ${3RDPARTY_JEMALLOC_LIBRARY_${PREFIX}_${MMGR_LIB}} NAME) + list(APPEND CSF_MMGR "${STATIC_LIB_NAME}") + set (JEMALLOC_IS_STATIC_LIB TRUE) +endif() +# install instructions +if (INSTALL_JEMALLOC AND NOT JEMALLOC_IS_STATIC_LIB) + OCCT_MAKE_OS_WITH_BITNESS() + OCCT_MAKE_COMPILER_SHORT_NAME() + get_filename_component(3RDPARTY_JEMALLOC_LIBRARY ${3RDPARTY_JEMALLOC_LIBRARY_${PREFIX}_${MMGR_LIB}} REALPATH) + if (SINGLE_GENERATOR) + install (FILES "${3RDPARTY_JEMALLOC_LIBRARY}" + DESTINATION "${INSTALL_DIR}/${INSTALL_DIR_LIB}") + else() + install (FILES "${3RDPARTY_JEMALLOC_LIBRARY}" + CONFIGURATIONS Debug + DESTINATION "${JEMALLOC_INSTALL_DESTINATION}d") + install (FILES "${3RDPARTY_JEMALLOC_LIBRARY}" + CONFIGURATIONS Release + DESTINATION "${JEMALLOC_INSTALL_DESTINATION}") + install (FILES "${3RDPARTY_JEMALLOC_LIBRARY}" + CONFIGURATIONS RelWithDebInfo + DESTINATION "${JEMALLOC_INSTALL_DESTINATION}i") + endif() + set (USED_3RDPARTY_JEMALLOC_DIR "") +elseif(NOT JEMALLOC_IS_STATIC_LIB) + # the library directory for using by the executable + set (USED_3RDPARTY_JEMALLOC_DIR ${3RDPARTY_JEMALLOC_LIBRARY_DIR_${MMGR_LIB}}) +endif() +unset(3RDPARTY_JEMALLOC_LIBRARY_DIR_${MMGR_LIB} CACHE) +unset(3RDPARTY_JEMALLOC_LIBRARY_${PREFIX}_${MMGR_LIB} CACHE) +endmacro() + +# Reset CSF variable +set (CSF_MMGR "") + +# find static jemalloc lib +SET(CMAKE_FIND_LIBRARY_SUFFIXES ".lib" ".a") +if (WIN32) + JEMALLOC_LIB_SEARCH ("jemalloc" "STATIC") +elseif(NOT WIN32) + JEMALLOC_LIB_SEARCH ("jemalloc_pic" "STATIC") + SET(CMAKE_FIND_LIBRARY_SUFFIXES "" "so") + JEMALLOC_LIB_SEARCH ("jemalloc.so.2" "SHARED") +endif() + +# find shared jemalloc lib +SET(CMAKE_FIND_LIBRARY_SUFFIXES ".dll" ".so") +JEMALLOC_LIB_SEARCH ("jemalloc" "SHARED") diff --git a/adm/templates/custom.build.bat.in b/adm/templates/custom.build.bat.in index 39ad45085b..b968dc854a 100644 --- a/adm/templates/custom.build.bat.in +++ b/adm/templates/custom.build.bat.in @@ -14,6 +14,7 @@ if /I "%VCVER%" == "@COMPILER@" ( set "TBB_DIR=@3RDPARTY_TBB_DLL_DIR@" set "VTK_DIR=@3RDPARTY_VTK_DLL_DIR@" set "FFMPEG_DIR=@3RDPARTY_FFMPEG_DLL_DIR@" + set "JEMALLOC_DIR=@3RDPARTY_JEMALLOC_LIBRARY_DIR@" set "OPENVR_DIR=@3RDPARTY_OPENVR_DLL_DIRS@" if not "@3RDPARTY_QT_DIR@" == "" ( diff --git a/adm/templates/custom.build.sh.in b/adm/templates/custom.build.sh.in index 1f3d2018be..bcf340164e 100644 --- a/adm/templates/custom.build.sh.in +++ b/adm/templates/custom.build.sh.in @@ -12,6 +12,7 @@ if [ "$1" == "@BIN_LETTER@" ]; then export TBB_DIR="@3RDPARTY_TBB_LIBRARY_DIR@" export VTK_DIR="@3RDPARTY_VTK_LIBRARY_DIR@" export FFMPEG_DIR="@3RDPARTY_FFMPEG_LIBRARY_DIR@" + export JEMALLOC_DIR="@3RDPARTY_JEMALLOC_LIBRARY_DIR@" if [ "x@3RDPARTY_QT_DIR" != "x" ]; then export QTDIR="@3RDPARTY_QT_DIR@" diff --git a/adm/templates/custom.install.bat.in b/adm/templates/custom.install.bat.in index 041152bdda..2f2af3a5ac 100644 --- a/adm/templates/custom.install.bat.in +++ b/adm/templates/custom.install.bat.in @@ -16,6 +16,7 @@ if /I "%VCVER%" == "@COMPILER@" ( set "TBB_DIR=@USED_3RDPARTY_TBB_DIR@" set "VTK_DIR=@USED_3RDPARTY_VTK_DIR@" set "FFMPEG_DIR=@USED_3RDPARTY_FFMPEG_DIR@" + set "JEMALLOC_DIR=@USED_3RDPARTY_JEMALLOC_DIR@" set "OPENVR_DIR=@USED_3RDPARTY_OPENVR_DIR@" if not "@USED_3RDPARTY_QT_DIR@" == "" ( diff --git a/adm/templates/custom.install.sh.in b/adm/templates/custom.install.sh.in index 79a4fa3a70..dc6552b342 100644 --- a/adm/templates/custom.install.sh.in +++ b/adm/templates/custom.install.sh.in @@ -12,6 +12,7 @@ if [ "$1" == "@BIN_LETTER@" ]; then export TBB_DIR="@USED_3RDPARTY_TBB_DIR@" export VTK_DIR="@USED_3RDPARTY_VTK_DIR@" export FFMPEG_DIR="@USED_3RDPARTY_FFMPEG_DIR@" + export JEMALLOC_DIR="@USED_3RDPARTY_JEMALLOC_DIR@" if [ "x@USED_3RDPARTY_QT_DIR@" != "x" ]; then export QTDIR="@USED_3RDPARTY_QT_DIR@" diff --git a/adm/templates/env.bat.in b/adm/templates/env.bat.in index 354a177cd1..24df954e68 100644 --- a/adm/templates/env.bat.in +++ b/adm/templates/env.bat.in @@ -154,6 +154,7 @@ if not ["%GLES2_DIR%"] == [""] set "PATH=%GLES2_DIR%;%PATH%" if not ["%TBB_DIR%"] == [""] set "PATH=%TBB_DIR%;%PATH%" if not ["%VTK_DIR%"] == [""] set "PATH=%VTK_DIR%;%PATH%" if not ["%FFMPEG_DIR%"] == [""] set "PATH=%FFMPEG_DIR%;%PATH%" +if not ["%JEMALLOC_DIR%"] == [""] set "PATH=%JEMALLOC_DIR%;%PATH%" if not ["%OPENVR_DIR%"] == [""] set "PATH=%OPENVR_DIR%;%PATH%" rem ----- Set path to 3rd party and OCCT libraries ----- diff --git a/adm/templates/env.build.sh.in b/adm/templates/env.build.sh.in index 7e11c6299e..3026d4c1f1 100644 --- a/adm/templates/env.build.sh.in +++ b/adm/templates/env.build.sh.in @@ -69,6 +69,10 @@ if [ "$FFMPEG_DIR" != "" ]; then THRDPARTY_PATH="${FFMPEG_DIR}:${THRDPARTY_PATH}" fi +if [ "$JEMALLOC_DIR" != "" ]; then + THRDPARTY_PATH="${JEMALLOC_DIR}:${THRDPARTY_PATH}" +fi + if [ "$QTDIR" != "" ]; then THRDPARTY_PATH="${QTDIR}/lib:${THRDPARTY_PATH}" fi diff --git a/adm/templates/env.install.sh.in b/adm/templates/env.install.sh.in index bdb2dec2fb..36254ff8cb 100644 --- a/adm/templates/env.install.sh.in +++ b/adm/templates/env.install.sh.in @@ -71,6 +71,10 @@ if [ "$FFMPEG_DIR" != "" ]; then THRDPARTY_PATH="${FFMPEG_DIR}:${THRDPARTY_PATH}" fi +if [ "$JEMALLOC_DIR" != "" ]; then + THRDPARTY_PATH="${JEMALLOC_DIR}:${THRDPARTY_PATH}" +fi + if [ "$QTDIR" != "" ]; then THRDPARTY_PATH="${QTDIR}/lib:${THRDPARTY_PATH}" fi diff --git a/src/Standard/Standard.cxx b/src/Standard/Standard.cxx index 49bafea57d..bb06de71fd 100644 --- a/src/Standard/Standard.cxx +++ b/src/Standard/Standard.cxx @@ -31,9 +31,6 @@ extern "C" int posix_memalign(void** thePtr, size_t theAlign, size_t theSize); #endif -// Temp define, after it will be part of CMake -#define OCCT_MMGT_OPT_NATIVE - namespace { static Standard::AllocatorType& allocatorTypeInstance() @@ -41,12 +38,12 @@ namespace static Standard::AllocatorType aType = #ifdef OCCT_MMGT_OPT_FLEXIBLE Standard::AllocatorType::NATIVE; -#elif defined OCCT_MMGT_OPT_NATIVE - Standard::AllocatorType::NATIVE; #elif defined OCCT_MMGT_OPT_TBB Standard::AllocatorType::TBB; #elif defined OCCT_MMGT_OPT_JEMALLOC Standard::AllocatorType::JEMALLOC; +#else + Standard::AllocatorType::NATIVE; #endif return aType; } @@ -54,9 +51,22 @@ namespace #ifdef OCCT_MMGT_OPT_JEMALLOC #define JEMALLOC_NO_DEMANGLE -#include +#include #endif // OCCT_MMGT_OPT_JEMALLOC +// paralleling with Intel TBB +#ifdef HAVE_TBB +#include +#else +#ifdef OCCT_MMGT_OPT_TBB +#undef OCCT_MMGT_OPT_TBB +#endif +#define scalable_malloc malloc +#define scalable_calloc calloc +#define scalable_realloc realloc +#define scalable_free free +#endif + // Available macros definition // - OCCT_MMGT_OPT_FLEXIBLE, modifiable in real time // - OCCT_MMGT_OPT_TBB, using tbb::scalable_allocator @@ -66,17 +76,6 @@ namespace #include #include - // paralleling with Intel TBB -#ifdef HAVE_TBB -#pragma comment (lib, "tbbmalloc.lib") -#include -#else -#define scalable_malloc malloc -#define scalable_calloc calloc -#define scalable_realloc realloc -#define scalable_free free -#endif - // There is no support for environment variables in UWP // OSD_Environment could not be used here because of cyclic dependency #ifdef OCCT_UWP @@ -119,13 +118,13 @@ namespace Standard_Address Reallocate(Standard_Address thePtr, const Standard_Size theSize) override { - Standard_Address newStorage = (Standard_Address)realloc(thePtr, theSize); - if (!newStorage) + Standard_Address aNewStorage = (Standard_Address)realloc(thePtr, theSize); + if (!aNewStorage) throw Standard_OutOfMemory("Standard_MMgrRaw::Reallocate(): realloc failed"); // Note that it is not possible to ensure that additional memory // allocated by realloc will be cleared (so as to satisfy myClear mode); // in order to do that we would need using memset... - return newStorage; + return aNewStorage; } //! Free allocated memory. The pointer is nullified. @@ -169,13 +168,13 @@ namespace Standard_Address Reallocate(Standard_Address thePtr, const Standard_Size theSize) override { - Standard_Address newStorage = (Standard_Address)scalable_realloc(thePtr, theSize); - if (!newStorage) + Standard_Address aNewStorage = (Standard_Address)scalable_realloc(thePtr, theSize); + if (!aNewStorage) throw Standard_OutOfMemory("Standard_MMgrTBBalloc::Reallocate(): realloc failed"); // Note that it is not possible to ensure that additional memory // allocated by realloc will be cleared (so as to satisfy myClear mode); // in order to do that we would need using memset... - return newStorage; + return aNewStorage; } //! Free allocated memory @@ -392,13 +391,18 @@ Standard_Address Standard::Allocate(const Standard_Size theSize) { #ifdef OCCT_MMGT_OPT_FLEXIBLE return Standard_MMgrFactory::GetMMgr()->Allocate(theSize); -#elif defined OCCT_MMGT_OPT_NATIVE - Standard_Address aPtr = calloc(theSize, sizeof(char)); +#elif defined OCCT_MMGT_OPT_JEMALLOC + Standard_Address aPtr = je_calloc(theSize, sizeof(char)); if (!aPtr) throw Standard_OutOfMemory("Standard_MMgrRaw::Allocate(): malloc failed"); return aPtr; -#elif defined OCCT_MMGT_OPT_JEMALLOC - Standard_Address aPtr = je_calloc(theSize, sizeof(char)); +#elif defined OCCT_MMGT_OPT_TBB + Standard_Address aPtr = scalable_calloc(theSize, sizeof(char)); + if (!aPtr) + throw Standard_OutOfMemory("Standard_MMgrRaw::Allocate(): malloc failed"); + return aPtr; +#else + Standard_Address aPtr = calloc(theSize, sizeof(char)); if (!aPtr) throw Standard_OutOfMemory("Standard_MMgrRaw::Allocate(): malloc failed"); return aPtr; @@ -413,10 +417,12 @@ Standard_Address Standard::AllocateOptimal(const Standard_Size theSize) { #ifdef OCCT_MMGT_OPT_FLEXIBLE return Standard_MMgrFactory::GetMMgr()->Allocate(theSize); -#elif defined OCCT_MMGT_OPT_NATIVE - return malloc(theSize); #elif defined OCCT_MMGT_OPT_JEMALLOC return je_malloc(theSize); +#elif defined OCCT_MMGT_OPT_TBB + return scalable_malloc(theSize); +#else + return malloc(theSize); #endif } @@ -428,10 +434,12 @@ void Standard::Free(Standard_Address theStorage) { #ifdef OCCT_MMGT_OPT_FLEXIBLE Standard_MMgrFactory::GetMMgr()->Free(theStorage); -#elif defined OCCT_MMGT_OPT_NATIVE - free(theStorage); #elif defined OCCT_MMGT_OPT_JEMALLOC - return je_free(theStorage); + je_free(theStorage); +#elif defined OCCT_MMGT_OPT_TBB + scalable_free(theStorage); +#else + free(theStorage); #endif } @@ -447,16 +455,21 @@ Standard_Address Standard::Reallocate(Standard_Address theStorage, // in order to do that we would need using memset.. #ifdef OCCT_MMGT_OPT_FLEXIBLE return Standard_MMgrFactory::GetMMgr()->Reallocate(theStorage, theSize); -#elif defined OCCT_MMGT_OPT_NATIVE +#elif defined OCCT_MMGT_OPT_JEMALLOC + Standard_Address aNewStorage = (Standard_Address)je_realloc(theStorage, theSize); + if (!aNewStorage) + throw Standard_OutOfMemory("Standard_MMgrRaw::Reallocate(): realloc failed"); + return aNewStorage; +#elif defined OCCT_MMGT_OPT_TBB + Standard_Address aNewStorage = (Standard_Address)scalable_realloc(theStorage, theSize); + if (!aNewStorage) + throw Standard_OutOfMemory("Standard_MMgrRaw::Reallocate(): realloc failed"); + return aNewStorage; +#else Standard_Address aNewStorage = (Standard_Address)realloc(theStorage, theSize); if (!aNewStorage) throw Standard_OutOfMemory("Standard_MMgrRaw::Reallocate(): realloc failed"); return aNewStorage; -#elif defined OCCT_MMGT_OPT_JEMALLOC - Standard_Address newStorage = (Standard_Address)je_realloc(theStorage, theSize); - if (!newStorage) - throw Standard_OutOfMemory("Standard_MMgrRaw::Reallocate(): realloc failed"); - return newStorage; #endif } @@ -480,7 +493,11 @@ Standard_Integer Standard::Purge() Standard_Address Standard::AllocateAligned(const Standard_Size theSize, const Standard_Size theAlign) { -#if defined(OCCT_MMGT_OPT_FLEXIBLE) || defined(OCCT_MMGT_OPT_NATIVE) +#ifdef OCCT_MMGT_OPT_JEMALLOC + return je_aligned_alloc(theAlign, theSize); +#elif defined OCCT_MMGT_OPT_TBB + return scalable_aligned_malloc(theSize, theAlign); +#else #if defined(_MSC_VER) return _aligned_malloc(theSize, theAlign); #elif defined(__ANDROID__) || defined(__QNX__) @@ -495,8 +512,6 @@ Standard_Address Standard::AllocateAligned(const Standard_Size theSize, } return aPtr; #endif -#elif defined OCCT_MMGT_OPT_JEMALLOC - return je_aligned_alloc(theAlign, theSize); #endif } @@ -506,7 +521,11 @@ Standard_Address Standard::AllocateAligned(const Standard_Size theSize, //======================================================================= void Standard::FreeAligned(Standard_Address thePtrAligned) { -#if defined(OCCT_MMGT_OPT_FLEXIBLE) || defined(OCCT_MMGT_OPT_NATIVE) +#ifdef OCCT_MMGT_OPT_JEMALLOC +return je_free(thePtrAligned); +#elif defined OCCT_MMGT_OPT_TBB + return scalable_aligned_free(thePtrAligned); +#else #if defined(_MSC_VER) _aligned_free(thePtrAligned); #elif defined(__ANDROID__) || defined(__QNX__) @@ -516,7 +535,5 @@ void Standard::FreeAligned(Standard_Address thePtrAligned) #else free(thePtrAligned); #endif -#elif defined OCCT_MMGT_OPT_JEMALLOC - return je_free(thePtrAligned); #endif } diff --git a/src/TKernel/CMakeLists.txt b/src/TKernel/CMakeLists.txt index aa2ddb052d..f3f74c09d8 100644 --- a/src/TKernel/CMakeLists.txt +++ b/src/TKernel/CMakeLists.txt @@ -1,3 +1,14 @@ project(TKernel) OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit) + +# Set desired Memory Manager +if ("${USE_MMGR_TYPE}" STREQUAL "FLEXIBLE") + target_compile_definitions("TKernel" PRIVATE "OCCT_MMGT_OPT_FLEXIBLE") +elseif ("${USE_MMGR_TYPE}" STREQUAL "TBB") + target_compile_definitions("TKernel" PRIVATE "OCCT_MMGT_OPT_TBB") +elseif ("${USE_MMGR_TYPE}" STREQUAL "JEMALLOC") + target_compile_definitions("TKernel" PRIVATE "OCCT_MMGT_OPT_JEMALLOC") +else () + message (STATUS "Info: Used native memory manager") +endif() diff --git a/src/TKernel/EXTERNLIB b/src/TKernel/EXTERNLIB index 8911ab53c5..1c9d77f47f 100755 --- a/src/TKernel/EXTERNLIB +++ b/src/TKernel/EXTERNLIB @@ -7,3 +7,4 @@ CSF_dl CSF_wsock32 CSF_psapi CSF_androidlog +CSF_MMGR