]> OCCT Git - occt.git/commitdiff
0033425: Configuration - Implement JeMalloc memory manager
authordpasukhi <dpasukhi@opencascade.com>
Wed, 22 Nov 2023 11:49:24 +0000 (11:49 +0000)
committerdpasukhi <dpasukhi@opencascade.com>
Mon, 4 Dec 2023 13:38:51 +0000 (13:38 +0000)
Integrated CMake procedure to choose MMGR
Default MMGE is Native

12 files changed:
CMakeLists.txt
adm/cmake/jemalloc.cmake [new file with mode: 0644]
adm/templates/custom.build.bat.in
adm/templates/custom.build.sh.in
adm/templates/custom.install.bat.in
adm/templates/custom.install.sh.in
adm/templates/env.bat.in
adm/templates/env.build.sh.in
adm/templates/env.install.sh.in
src/Standard/Standard.cxx
src/TKernel/CMakeLists.txt
src/TKernel/EXTERNLIB

index 1bacca1a482fda47f303f068b55f01a011b66b76..5ef2cb161b204a23b45a54dd8f1baad05abfdb5b 100644 (file)
@@ -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 (file)
index 0000000..b37d5d2
--- /dev/null
@@ -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")
index 39ad45085be94285588d43eb80ff76d1894b485b..b968dc854aa69d92d804b02d12c8100528ebe8cc 100644 (file)
@@ -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@" == "" (
index 1f3d2018bea0e67243a2705f7d55f54f6e2a543a..bcf340164eab5098b1d0381e7f6ddd7e002c1a2e 100644 (file)
@@ -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@"
index 041152bddae5ec79e7f9b36d4e9737b796d2e696..2f2af3a5ac1ed89ae9b254411c7fdbed95825bdf 100644 (file)
@@ -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@" == "" (
index 79a4fa3a70f5238a11ac3a6f097ceed2e8251b3c..dc6552b3428d37e158507f0791f1f4f1eb06c79f 100644 (file)
@@ -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@"
index 354a177cd1d3a902d14c6d2327d55f9a843ab0aa..24df954e68ac140a86d30f4ae6367da210241490 100644 (file)
@@ -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 -----
index 7e11c6299e2a467fe3256bfc0dbde33e04002e17..3026d4c1f1c1c6b7d54d25294e51b7c5f0e9157a 100644 (file)
@@ -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
index bdb2dec2fbbb594dff4f557783fabc14c335f344..36254ff8cb688fa7f57832ae09f6f480f86c7e0e 100644 (file)
@@ -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
index 49bafea57d9f0348de5aea9a2d487da70f725e7c..bb06de71fd16ee578cb374f1945c0b5839aa0690 100644 (file)
@@ -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,29 +51,31 @@ namespace
 
 #ifdef OCCT_MMGT_OPT_JEMALLOC
 #define JEMALLOC_NO_DEMANGLE
-#include <jemalloc/jemalloc.h>
+#include <jemalloc.h>
 #endif // OCCT_MMGT_OPT_JEMALLOC
 
-// Available macros definition
-// - OCCT_MMGT_OPT_FLEXIBLE, modifiable in real time
-// - OCCT_MMGT_OPT_TBB, using tbb::scalable_allocator
-// - OCCT_MMGT_OPT_NATIVE, using native calloc, free
-// - OCCT_MMGT_OPT_JEMALLOC, using external jecalloc, jefree
-#ifdef OCCT_MMGT_OPT_FLEXIBLE
-#include <Standard_MMgrOpt.hxx>
-#include <Standard_Assert.hxx>
-
-  // paralleling with Intel TBB
+// paralleling with Intel TBB
 #ifdef HAVE_TBB
-#pragma comment (lib, "tbbmalloc.lib")
 #include <tbb/scalable_allocator.h>
 #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
+// - OCCT_MMGT_OPT_NATIVE, using native calloc, free
+// - OCCT_MMGT_OPT_JEMALLOC, using external jecalloc, jefree
+#ifdef OCCT_MMGT_OPT_FLEXIBLE
+#include <Standard_MMgrOpt.hxx>
+#include <Standard_Assert.hxx>
+
 // 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
-  Standard_Address aNewStorage = (Standard_Address)realloc(theStorage, theSize);
+#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_JEMALLOC
-  Standard_Address newStorage = (Standard_Address)je_realloc(theStorage, theSize);
-  if (!newStorage)
+#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 newStorage;
+  return aNewStorage;
+#else
+  Standard_Address aNewStorage = (Standard_Address)realloc(theStorage, theSize);
+  if (!aNewStorage)
+    throw Standard_OutOfMemory("Standard_MMgrRaw::Reallocate(): realloc failed");
+  return aNewStorage;
 #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
 }
index aa2ddb052d2f3d833fb673769b84417fdac611a3..f3f74c09d8cd526db007bb3f3b5821021a4c6626 100644 (file)
@@ -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()
index 8911ab53c50915d78009a730648a8b47120d9033..1c9d77f47f6fd0c6293a5eeed6b4d46f6c403b54 100755 (executable)
@@ -7,3 +7,4 @@ CSF_dl
 CSF_wsock32
 CSF_psapi
 CSF_androidlog
+CSF_MMGR