Salome HOME
Memory usage optimization for Builders on big tags creation (like Partition).
authormpv <mpv@opencascade.com>
Fri, 7 Jul 2017 05:56:50 +0000 (08:56 +0300)
committermpv <mpv@opencascade.com>
Fri, 7 Jul 2017 05:56:50 +0000 (08:56 +0300)
src/Model/Model_BodyBuilder.cpp
src/Model/Model_BodyBuilder.h

index 383661d8642f75678ef6a7f92a55015e398f3455..9c143aef815a79ce0d029b73a188cb4a307ccb45 100755 (executable)
@@ -251,9 +251,9 @@ void  Model_BodyBuilder::storeWithoutNaming(const std::shared_ptr<GeomAPI_Shape>
 
 void Model_BodyBuilder::clean()
 {
-  std::vector<TNaming_Builder*>::iterator aBuilder = myBuilders.begin();
+  std::map<int, TNaming_Builder*>::iterator aBuilder = myBuilders.begin();
   for(; aBuilder != myBuilders.end(); aBuilder++)
-    delete *aBuilder;
+    delete aBuilder->second;
   myBuilders.clear();
 }
 
@@ -264,17 +264,13 @@ Model_BodyBuilder::~Model_BodyBuilder()
 
 TNaming_Builder* Model_BodyBuilder::builder(const int theTag)
 {
-  if (myBuilders.size() <= (unsigned int)theTag) {
-    myBuilders.insert(myBuilders.end(), theTag - myBuilders.size() + 1, NULL);
-  }
-  if (!myBuilders[theTag]) {
+  std::map<int, TNaming_Builder*>::iterator aFind = myBuilders.find(theTag);
+  if (aFind == myBuilders.end()) {
     std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
     myBuilders[theTag] = new TNaming_Builder(aData->shapeLab().FindChild(theTag));
-    //TCollection_AsciiString entry;//
-    //TDF_Tool::Entry(aData->shapeLab().FindChild(theTag), entry);
-    //cout << "Label = " <<entry.ToCString() <<endl;
+    aFind = myBuilders.find(theTag);
   }
-  return myBuilders[theTag];
+  return aFind->second;
 }
 
 void Model_BodyBuilder::buildName(const int theTag, const std::string& theName)
index f295e0864b469ade49d94a93fbe306f439486177..983c03a7564f5f7564d0e9a48c8641d721a1589a 100755 (executable)
@@ -36,9 +36,9 @@ class TNaming_Builder;
  */
 class Model_BodyBuilder : public ModelAPI_BodyBuilder
 {
-  /// builders that tores the naming history: one per label to allow store several shapes to one
+  /// builders that store the naming history: one per label to allow store several shapes to one
   /// label; index in vector corresponds to the label tag
-  std::vector<TNaming_Builder*> myBuilders;
+  std::map<int, TNaming_Builder*> myBuilders;
 public:
   /// Stores the shape (called by the execution method).
   MODEL_EXPORT virtual void store(const std::shared_ptr<GeomAPI_Shape>& theShape,