MantisBT - Community
View Issue Details
0023592Community[OCCT] OCCT:Foundation Classespublic2012-11-28 12:572013-08-12 13:47
Roman Lygin 
Roman Lygin 
normalintegration request 
[OCCT] 6.6.0[OCCT] 6.6.0 
Not needed
0023592: Enabling TBB allocator by default for OCC built with -DHAVE_TBB
Without the fix, OCC built with HAVE_TBB defaults to OS allocator (i.e. malloc(), free()), if the variable MMGT_OPT is not explicitly set to 2. This leads to poorer performance if the variable has not been set by a target application developer or in end-user environment. For library ISV's (e.g. in the case of CAD Exchanger SDK) there is no way to explicitly control the application developer and the end-user environment (when the application integrating the SDK is deployed at end user premise). It is also impossible (due to lack of API) to check which allocator has been actually chosen and to issue a corresponding warning and suggestion messages if it is not TBB the allocator that was chosen.
Defaulting to TBB allocator makes sense as this choice has been made during *build* time, when the library developer has deliberately made a decision to use TBB.
General note 1: ideally there should be a programmatic way (API) to dynamically set an instance of developer-defined allocator (subclass of Standard_MMgrRoot), e.g. not part of the Standard package. However this will require thorough analysis of feasibility (e.g. how to deal with static objects initialized during load time).
General note 2: influencing OCC behavior should be made more possible via API, not only via env vars. Even for application (not only library) developers, API can be more reliable and user-friendly approach. For greater flexibility influencing via env vars should be preserved, of course. But this is a general topic for broader roadmap discussion.
No tags attached.
related to 0024110assigned ysn OCCT_MMGT_OPT_DEFAULT macro support 
Issue History
2012-11-28 12:57Roman LyginNew Issue
2012-11-28 12:57Roman LyginAssigned To => abv
2012-11-28 13:01Roman LyginNote Added: 0022403
2012-11-28 13:01Roman LyginStatusnew => resolved
2012-11-28 13:08abvAssigned Toabv => Roman Lygin
2012-11-28 13:08abvStatusresolved => assigned
2012-11-28 13:10abvNote Added: 0022405
2012-11-28 14:46Roman LyginNote Added: 0022410
2012-11-28 15:14abvNote Added: 0022411
2012-11-28 16:59Roman LyginNote Added: 0022415
2012-11-29 21:45Roman LyginNote Added: 0022461
2012-11-29 22:04Roman LyginNote Added: 0022462
2012-11-29 22:05Roman LyginAssigned ToRoman Lygin => abv
2012-11-29 22:05Roman LyginStatusassigned => resolved
2012-11-30 13:48abvNote Added: 0022482
2012-11-30 13:48abvAssigned Toabv => bugmaster
2012-11-30 13:48abvStatusresolved => reviewed
2012-11-30 14:56mkvAssigned Tobugmaster => mkv
2012-12-03 14:46mkvNote Added: 0022514
2012-12-03 14:47mkvTest case number => Not needed
2012-12-03 14:47mkvAssigned Tomkv => bugmaster
2012-12-03 14:47mkvStatusreviewed => tested
2012-12-10 17:16Roman LyginChangeset attached => occt master a0d8a9fc
2012-12-10 17:16Roman LyginAssigned Tobugmaster => Roman Lygin
2012-12-10 17:16Roman LyginStatustested => verified
2012-12-10 17:16Roman LyginResolutionopen => fixed
2012-12-10 17:50bugmasterTarget Version => 6.6.0
2013-04-23 13:36aivStatusverified => closed
2013-04-29 15:21aivFixed in Version => 6.6.0
2013-08-12 13:47Roman LyginRelationship addedrelated to 0024110

Roman Lygin   
2012-11-28 13:01   
Pushed branch CR23592 into the git repository
2012-11-28 13:10   
I suggest that separate pre-processor macro (e.g. MMGT_OPT :-) can be added to manipulate default value of this parameter at build time. This would allow manipulating default setting independently of availability of TBB which is indicated by HAVE_TBB macro.
Roman Lygin   
2012-11-28 14:46   
Andrey, thanks for the idea. Do you suggest something like this:

in Standard.cxx:

Standard_Integer anAllocId = (aVar = getenv ("MMGT_OPT" )) ? atoi (aVar) : OCCT_MMGT_OPT_DEFAULT;

and the developer could add "OCCT_MMGT_OPT_DEFAULT=2" to CSF_DEFINES env var on Windows or /DOCCT_MMGT_OPT_DEFAULT=2 when configuring on Linux ?

That can make sense indeed.
Of course, respective amendments will have to be made:
a). in ros/env.bat as it currently only checks for HAVE_{TBB|FREEIMAGE|GL2PS} variables.
b). in documentation

Would you like me to do any/all of this or would you take some time to think over ? Please set bug ownership respectively.
2012-11-28 15:14   
Yes, that was an idea. If you agree, I suggest you do this (as the most interested person -- this will also ensure that it works as expected for you). For documentation update, just put your proposal in "Additional info..." field -- this should be taken into account by documentation engineers when building Release Notes.

As for update of the env.bat, I suppose it is not really needed, rather we need to document all #defines that affect OCCT builds.. but this is another story
Roman Lygin   
2012-11-28 16:59   
OK to prepare a modification.

Re preprocessor definitions on Windows: project files use %CSF_DEFINES%. So the developer has to set it prior to opening a project file, but the env.bat resets CSF_DEFINE to empty value and only recognizes HAVE_* vars. Thus, it has to be either be made aware of all supported macros, or to not erase CSF_DEFINE if it was set before launching env.bat. I am inclined to the latter for its greater flexibility.
Let me know if I miss anything.
Roman Lygin   
2012-11-29 21:45   
Standard.cxx pushed into the git repository.
Macro prefix OCCT has been chosen in accordance with 0022916.

env.bat is not available for modification, so here is a suggested one:
a). either remove these lines:
if not ["%OCCT_MMGT_OPT_DEFAULT"] == [""] (
Roman Lygin   
2012-11-29 22:04   
Amendments for the documentation.

1. Into OCC overview / Building Modules chapter:

a). Rebuilding on Windows.

under "use variable CSF_DEFINES to specify additional compiler macros:"

add as a separate bullet:

OCCT_MMGT_OPT_DEFAULT=value (where value is 0, 1 or 2) if you want to specify a memory allocator which will be used in run-time as a fallback in the case if the environment variable MMGT_OPT has not been explicitly defined.

b). Rebuilding on Linux with autoconf, automake and libtool scripts.

under "Additional flags:"

add as a separate bullet:

CXXFLAGS="-DOCCT_MMGT_OPT_DEFAULT=value" (where value is 0, 1 or 2) if you want to specify a memory allocator which will be used in run-time as a fallback in the case if the environment variable MMGT_OPT has not been explicitly defined.

2). Into Foundation Classes User's Guide.

Chapter 2.3.2. Configuring the memory manager

Under "MMGT_OPT:" bullet add as a sub-bullet.

Default value is defined in compile-time with the help of the pre-processor macro OCCT_MMGT_OPT_DEFAULT. If set, it must have a valid numeric value (0, 1 or 2). If not set (by default) then the value 0 will be used.
2012-11-30 13:48   
No remarks, please test. Note that I have pushed relevant modification in env.bat file (removal of line setting CSF_DEFINES to empty string) in WOK branch CR23592.
2012-12-03 14:46   
Dear BugMaster,
Branch CR23592 (and products from GIT master) was compiled on Linux and Windows platforms and tested.

Not detected

Not detected

Testing cases:
Not needed