Archived issue #0022816
Enhancement request: new[]/delete[] operators should be redefined to use OCC allocation
Description
Post from the Forum - http://www.opencascade.org/org/forum/thread_22253/.
RLN contribution.
"The new[] operator (e.g. used in arrays/vectors) is not redefined in OCC classes and thus does not take advantage of OCC memory allocation mechanism (Standard::Allocate(), Standard::Free()). Instead it defaults to standard new/delete [] operators.
Example:
TopTools_Array1OfShape anArray (1, 10);
will underneath call new TopoDS_Shape[10] which will NOT call Standard::Allocate().
We discussed this issue with ABV a while ago, so maybe there is already a bug registered. In this case, please just post an ID here for future tracking."
RLN contribution.
"The new[] operator (e.g. used in arrays/vectors) is not redefined in OCC classes and thus does not take advantage of OCC memory allocation mechanism (Standard::Allocate(), Standard::Free()). Instead it defaults to standard new/delete [] operators.
Example:
TopTools_Array1OfShape anArray (1, 10);
will underneath call new TopoDS_Shape[10] which will NOT call Standard::Allocate().
We discussed this issue with ABV a while ago, so maybe there is already a bug registered. In this case, please just post an ID here for future tracking."
Public activity
9 archived notes
Participants are labeled by their role within this record.
I suggest that along with this correction we pack all OCCT-specific declarations of new / delete into a macro (to be defined in Standard_Macro.hxx) and use it in all relevant classes.
Operators new[]/delete[] redefined in the macro OVERRIDE_MEMORY_OPERATORS (src/Standard/Standard_Macro.hxx) to use OCC allocation.
bug fixed in the branch: http://svn/svn/occt/branches/OCC22815
Dear Andrey,
Please review.
bug fixed in the branch: http://svn/svn/occt/branches/OCC22815
Dear Andrey,
Please review.
General comment:
Please think of a general policy of naming macros to ensure consistency and easy attribution to Open CASCADE. Often, macros are named with product prefix and underscores, for instance this could be:
__OCC_OVERRIDE_MEMORY_OPERATORS
Please think of a general policy of naming macros to ensure consistency and easy attribution to Open CASCADE. Often, macros are named with product prefix and underscores, for instance this could be:
__OCC_OVERRIDE_MEMORY_OPERATORS
See review remarks in #0022815
Roman is right, macros used in installed header files should be prefixed by OCC_ to avoid name clashes. But please do not use leading underscores, such names are reserved in C++.
Sure these names are reserved, thanks for commenting. We shall consider giving common prefix to macros in the future; in this particular fix I prefer to stick to using currently adopted pattern.
Workbench apn-OCC22815-occt/products was successfully tested in #0022815
Problem was solved by fix for issue 22815
Related records