From af09dbff2eeae5a5bc6f3f8fac8236397fbe4022 Mon Sep 17 00:00:00 2001 From: kgv Date: Wed, 21 Mar 2012 18:10:41 +0400 Subject: [PATCH] 0022627: Change OCCT memory management defaults --- src/Standard/Standard.cxx | 74 +++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 27 deletions(-) diff --git a/src/Standard/Standard.cxx b/src/Standard/Standard.cxx index 8e31453e90..13fee894e6 100755 --- a/src/Standard/Standard.cxx +++ b/src/Standard/Standard.cxx @@ -12,8 +12,13 @@ #include #include +#if(defined(_WIN32) || defined(__WIN32__)) +#include +#include +#endif + // Global reentrant flag -static Standard_Boolean Standard_IsReentrant = Standard_False; +static Standard_Boolean Standard_IsReentrant = Standard_True; //======================================================================= //class : Standard_MMgrFactory @@ -35,34 +40,49 @@ class Standard_MMgrFactory { //purpose : Check environment variables and create appropriate memory manager //======================================================================= -Standard_MMgrFactory::Standard_MMgrFactory() : myFMMgr(0) +Standard_MMgrFactory::Standard_MMgrFactory() +: myFMMgr (NULL) { - char *var; - Standard_Boolean bClear, bMMap, bReentrant; - Standard_Integer aCellSize, aNbPages, aThreshold, bOptAlloc; - // - bOptAlloc = atoi((var = getenv("MMGT_OPT" )) ? var : "1" ); - bClear = atoi((var = getenv("MMGT_CLEAR" )) ? var : "1" ); - bMMap = atoi((var = getenv("MMGT_MMAP" )) ? var : "1" ); - aCellSize = atoi((var = getenv("MMGT_CELLSIZE" )) ? var : "200" ); - aNbPages = atoi((var = getenv("MMGT_NBPAGES" )) ? var : "1000" ); - aThreshold = atoi((var = getenv("MMGT_THRESHOLD")) ? var : "40000"); - bReentrant = atoi((var = getenv("MMGT_REENTRANT")) ? var : "0" ); - - if ( bOptAlloc == 1 ) { - myFMMgr = new Standard_MMgrOpt(bClear, bMMap, aCellSize, aNbPages, - aThreshold, bReentrant); - } - else if ( bOptAlloc == 2 ) { - myFMMgr = new Standard_MMgrTBBalloc(bClear); - } - else { - myFMMgr = new Standard_MMgrRaw(bClear); - } + char* aVar; + Standard_Integer anAllocId = (aVar = getenv ("MMGT_OPT" )) ? atoi (aVar) : 0; + Standard_Boolean toClear = (aVar = getenv ("MMGT_CLEAR" )) ? (atoi (aVar) != 0) : Standard_True; - // Set grobal reentrant flag according to MMGT_REENTRANT environment variable - if ( ! Standard_IsReentrant ) - Standard_IsReentrant = bReentrant; + + // on Windows (actual for XP and 2000) activate low fragmentation heap + // for CRT heap in order to get best performance. + // Environment variable MMGT_LFH can be used to switch off this action (if set to 0) +#if defined(_MSC_VER) + aVar = getenv ("MMGT_LFH"); + if ( aVar == NULL || atoi (aVar) != 0 ) + { + ULONG aHeapInfo = 2; + HANDLE aCRTHeap = (HANDLE)_get_heap_handle(); + HeapSetInformation (aCRTHeap, HeapCompatibilityInformation, &aHeapInfo, sizeof(aHeapInfo)); + } +#endif + + aVar = getenv ("MMGT_REENTRANT"); + if ( aVar != NULL ) + Standard_IsReentrant = (atoi (aVar) != 0); + + switch (anAllocId) + { + case 1: // OCCT optimized memory allocator + { + Standard_Boolean bMMap = (aVar = getenv ("MMGT_MMAP" )) ? (atoi (aVar) != 0) : Standard_True; + Standard_Integer aCellSize = (aVar = getenv ("MMGT_CELLSIZE" )) ? atoi (aVar) : 200; + Standard_Integer aNbPages = (aVar = getenv ("MMGT_NBPAGES" )) ? atoi (aVar) : 1000; + Standard_Integer aThreshold = (aVar = getenv ("MMGT_THRESHOLD")) ? atoi (aVar) : 40000; + myFMMgr = new Standard_MMgrOpt (toClear, bMMap, aCellSize, aNbPages, aThreshold, Standard_IsReentrant); + break; + } + case 2: // TBB memory allocator + myFMMgr = new Standard_MMgrTBBalloc (toClear); + break; + case 0: + default: // system default memory allocator + myFMMgr = new Standard_MMgrRaw (toClear); + } } //=======================================================================