From 1edd8000008908cd21aaa745f40c5435a408cb1a Mon Sep 17 00:00:00 2001 From: Eric Mehl Date: Thu, 10 Oct 2024 12:50:27 -0400 Subject: [PATCH] GafferModule : Windows `verifyAllocator()` --- Changes.md | 2 +- bin/__gaffer.py | 3 +++ src/GafferModule/GafferModule.cpp | 28 ++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/Changes.md b/Changes.md index 6a87debe34d..68eb292032c 100644 --- a/Changes.md +++ b/Changes.md @@ -5,7 +5,7 @@ Improvements ------------ - Light Editor : Added `is_sphere` column for Cycles lights. - +- Windows : Gaffer now uses the TBB memory allocator for significantly better performance. 1.5.0.0a3 (relative to 1.5.0.0a2) diff --git a/bin/__gaffer.py b/bin/__gaffer.py index e9a616ba212..6aae17f4c47 100755 --- a/bin/__gaffer.py +++ b/bin/__gaffer.py @@ -56,6 +56,9 @@ import IECore +if os.name == "nt" : + Gaffer._Gaffer._verifyAllocator() + # Increase the soft limit for file handles as high as we can - we need everything we can get for # opening models, textures etc. if os.name != "nt" : diff --git a/src/GafferModule/GafferModule.cpp b/src/GafferModule/GafferModule.cpp index 82a92f7e723..f519db64283 100644 --- a/src/GafferModule/GafferModule.cpp +++ b/src/GafferModule/GafferModule.cpp @@ -93,6 +93,12 @@ #include #endif +#ifdef _MSC_VER +#include "IECore/MessageHandler.h" + +#include "tbb/tbbmalloc_proxy.h" +#endif + using namespace boost::python; using namespace Gaffer; using namespace GafferModule; @@ -187,6 +193,25 @@ void nameProcess() #endif } +#ifdef _MSC_VER +void verifyAllocator() +{ + + char **replacementLog; + int replacementStatus = TBB_malloc_replacement_log( &replacementLog ); + + if( replacementStatus != 0 ) + { + IECore::msg( IECore::Msg::Warning, "Gaffer", "Failed to install TBB memory allocator. Performance may be degraded." ); + for( char **logEntry = replacementLog; *logEntry != 0; logEntry++ ) + { + IECore::msg( IECore::Msg::Warning, "Gaffer", *logEntry ); + } + } + +} +#endif + } // namespace // Arrange for `storeArgcArgv()` to be called when our module loads, @@ -257,5 +282,8 @@ BOOST_PYTHON_MODULE( _Gaffer ) def( "isDebug", &isDebug ); def( "_nameProcess", &nameProcess ); +#ifdef _MSC_VER + def( "_verifyAllocator", &verifyAllocator ); +#endif }