Ignore:
Timestamp:
May 31, 2010, 1:09:58 PM (15 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
42af9e
Parents:
87b597
Message:

Removed all Malloc/Calloc/ReAlloc (&Free) and replaced by new and delete/delete[].

Due to the new MemDebug framework there is no need (or even unnecessary/unwanted competition between it and) for the MemoryAllocator and ..UsageObserver anymore.
They can however still be used with c codes such as pcp and alikes.

In Molecuilder lots of glibc corruptions arose and the C-like syntax make it generally harder to get allocation and deallocation straight.

Signed-off-by: Frederik Heber <heber@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/molecule_fragmentation.cpp

    r87b597 r920c70  
    9494  GraphTestPair testGraphInsert;
    9595  int NumberOfFragments = 0;
    96   char *filename = Malloc<char>(MAXSTRINGSIZE, "molecule::ParseKeySetFile - filename");
     96  char filename[MAXSTRINGSIZE];
    9797
    9898  if (FragmentList == NULL) { // check list pointer
     
    106106  if (InputFile != NULL) {
    107107    // each line represents a new fragment
    108     char *buffer = Malloc<char>(MAXSTRINGSIZE, "molecule::ParseKeySetFile - *buffer");
     108    char buffer[MAXSTRINGSIZE];
    109109    // 1. parse keysets and insert into temp. graph
    110110    while (!InputFile.eof()) {
     
    122122    InputFile.close();
    123123    InputFile.clear();
    124     Free(&buffer);
    125124    DoLog(1) && (Log() << Verbose(1) << "done." << endl);
    126125  } else {
     
    129128  }
    130129
    131   Free(&filename);
    132130  return status;
    133131};
     
    148146  int NumberOfFragments = 0;
    149147  double TEFactor;
    150   char *filename = Malloc<char>(MAXSTRINGSIZE, "molecule::ParseTEFactorsFile - filename");
     148  char filename[MAXSTRINGSIZE];
    151149
    152150  if (FragmentList == NULL) { // check list pointer
     
    179177  }
    180178
    181   // free memory
    182   Free(&filename);
    183 
    184179  return status;
    185180};
     
    317312  int No = 0, FragOrder = 0;
    318313  double Value = 0.;
    319   char *buffer = Malloc<char>(MAXSTRINGSIZE, "molecule::CheckOrderAtSite: *buffer");
     314  char buffer[MAXSTRINGSIZE];
    320315  sprintf(buffer, "%s/%s%s.dat", path, FRAGMENTPREFIX, ENERGYPERFRAGMENT);
    321316  ifstream InputFile(buffer, ios::in);
     
    345340    InputFile.clear();
    346341  }
    347   Free(&buffer);
    348342
    349343  return AdaptiveCriteriaList;
     
    474468    MarkUpdateCandidates(AtomMask, *FinalRootCandidates, Order, this);
    475469
    476     Free(&IndexKeySetList);
    477     Free(&AdaptiveCriteriaList);
    478     Free(&FinalRootCandidates);
     470    delete[](IndexKeySetList);
     471    delete[](AdaptiveCriteriaList);
     472    delete[](FinalRootCandidates);
    479473  } else { // global increase of Bond Order
    480474    while (Walker->next != end) {
     
    516510    return false;
    517511  }
    518   SortIndex = Malloc<int>(AtomCount, "molecule::CreateMappingLabelsToConfigSequence: *SortIndex");
     512  SortIndex = new int[AtomCount];
    519513  for(int i=AtomCount;i--;)
    520514    SortIndex[i] = -1;
     
    522516  int AtomNo = 0;
    523517  SetIndexedArrayForEachAtomTo( SortIndex, &atom::nr, &IncrementalAbsoluteValue, AtomNo );
     518  delete[](SortIndex);
    524519
    525520  return true;
     
    580575  // === compare it with adjacency file ===
    581576  FragmentationToDo = FragmentationToDo && CheckAdjacencyFileAgainstMolecule(configuration->configpath, ListOfAtoms);
    582   Free(&ListOfAtoms);
     577  delete[](ListOfAtoms);
    583578
    584579  // ===== 2. perform a DFS analysis to gather info on cyclic structure and a list of disconnected subgraphs =====
     
    672667    delete(Subgraphs);
    673668  }
    674   Free(&FragmentList);
     669  delete[](FragmentList);
    675670
    676671  // ===== 8b. gather keyset lists (graphs) from all subgraphs and transform into MoleculeListClass =====
     
    704699    StoreKeySetFile(TotalGraph, configuration->configpath);
    705700
    706     // store Adjacency file
    707     char *filename = Malloc<char> (MAXSTRINGSIZE, "molecule::FragmentMolecule - *filename");
    708     strcpy(filename, FRAGMENTPREFIX);
    709     strcat(filename, ADJACENCYFILE);
    710     StoreAdjacencyToFile(configuration->configpath, filename);
    711     Free(&filename);
     701    {
     702      // store Adjacency file
     703      char filename[MAXSTRINGSIZE];
     704      strcpy(filename, FRAGMENTPREFIX);
     705      strcat(filename, ADJACENCYFILE);
     706      StoreAdjacencyToFile(configuration->configpath, filename);
     707    }
    712708
    713709    // store Hydrogen saturation correction file
     
    722718    // free memory for bond part
    723719    DoLog(1) && (Log() << Verbose(1) << "Freeing bond memory" << endl);
    724     Free(&FragmentList); // remove bond molecule from memory
    725     Free(&SortIndex);
     720    delete[](FragmentList); // remove bond molecule from memory
     721    delete[](SortIndex);
    726722  } else {
    727723    DoLog(1) && (Log() << Verbose(1) << "FragmentList is zero on return, splitting failed." << endl);
     
    768764bool molecule::ParseOrderAtSiteFromFile(char *path)
    769765{
    770   unsigned char *OrderArray = Calloc<unsigned char>(AtomCount, "molecule::ParseOrderAtSiteFromFile - *OrderArray");
    771   bool *MaxArray = Calloc<bool>(AtomCount, "molecule::ParseOrderAtSiteFromFile - *MaxArray");
     766  unsigned char *OrderArray = new unsigned char[AtomCount];
     767  bool *MaxArray = new bool[AtomCount];
    772768  bool status;
    773769  int AtomNr, value;
    774770  stringstream line;
    775771  ifstream file;
     772
     773  for(int i=0;i<AtomCount;i++) {
     774    OrderArray[i] = 0;
     775    MaxArray[i] = false;
     776  }
    776777
    777778  DoLog(1) && (Log() << Verbose(1) << "Begin of ParseOrderAtSiteFromFile" << endl);
     
    802803    status = false;
    803804  }
    804   Free(&OrderArray);
    805   Free(&MaxArray);
     805  delete[](OrderArray);
     806  delete[](MaxArray);
    806807
    807808  DoLog(1) && (Log() << Verbose(1) << "End of ParseOrderAtSiteFromFile" << endl);
     
    929930molecule * molecule::StoreFragmentFromKeySet(KeySet &Leaflet, bool IsAngstroem)
    930931{
    931   atom **SonList = Calloc<atom*>(AtomCount, "molecule::StoreFragmentFromStack: **SonList");
     932  atom **SonList = new atom*[AtomCount];
    932933  molecule *Leaf = World::getInstance().createMolecule();
     934
     935  for(int i=0;i<AtomCount;i++)
     936    SonList[i] = NULL;
    933937
    934938//  Log() << Verbose(1) << "Begin of StoreFragmentFromKeyset." << endl;
     
    939943
    940944  //Leaflet->Leaf->ScanForPeriodicCorrection(out);
    941   Free(&SonList);
     945  delete[](SonList);
    942946//  Log() << Verbose(1) << "End of StoreFragmentFromKeyset." << endl;
    943947  return Leaf;
     
    10841088  int bits, TouchedIndex, SubSetDimension, SP, Added;
    10851089  int SpaceLeft;
    1086   int *TouchedList = Malloc<int>(SubOrder + 1, "molecule::SPFragmentGenerator: *TouchedList");
     1090  int *TouchedList = new int[SubOrder + 1];
    10871091  bond **BondsList = NULL;
    10881092  KeySetTestPair TestKeySetInsert;
     
    11241128
    11251129          // then allocate and fill the list
    1126           BondsList = Malloc<bond*>(SubSetDimension, "molecule::SPFragmentGenerator: **BondsList");
     1130          bond *BondsList[SubSetDimension];
    11271131          SubSetDimension = FillBondsList(BondsList, FragmentSearch->BondsPerSPList[2*SP], FragmentSearch->BondsPerSPList[2*SP+1], TouchedList, TouchedIndex);
    11281132
     
    11301134          Log() << Verbose(2+verbosity) << "Calling subset generator " << SP << " away from root " << *FragmentSearch->Root << " with sub set dimension " << SubSetDimension << "." << endl;
    11311135          SPFragmentGenerator(FragmentSearch, SP, BondsList, SubSetDimension, SubOrder-bits);
    1132 
    1133           Free(&BondsList);
    11341136        }
    11351137      } else {
     
    11531155    }
    11541156  }
    1155   Free(&TouchedList);
     1157  delete[](TouchedList);
    11561158  Log() << Verbose(1+verbosity) << "End of SPFragmentGenerator, " << RootDistance << " away from Root " << *FragmentSearch->Root << " and SubOrder is " << SubOrder << "." << endl;
    11571159};
     
    11651167void InitialiseSPList(int Order, struct UniqueFragments &FragmentSearch)
    11661168{
    1167   FragmentSearch.BondsPerSPList = Malloc<bond*>(Order * 2, "molecule::PowerSetGenerator: ***BondsPerSPList");
    1168   FragmentSearch.BondsPerSPCount = Malloc<int>(Order, "molecule::PowerSetGenerator: *BondsPerSPCount");
     1169  FragmentSearch.BondsPerSPList = new bond* [Order * 2];
     1170  FragmentSearch.BondsPerSPCount = new int[Order];
    11691171  for (int i=Order;i--;) {
    11701172    FragmentSearch.BondsPerSPList[2*i] = new bond();    // start node
     
    11841186void FreeSPList(int Order, struct UniqueFragments &FragmentSearch)
    11851187{
    1186   Free(&FragmentSearch.BondsPerSPCount);
     1188  delete[](FragmentSearch.BondsPerSPCount);
    11871189  for (int i=Order;i--;) {
    11881190    delete(FragmentSearch.BondsPerSPList[2*i]);
    11891191    delete(FragmentSearch.BondsPerSPList[2*i+1]);
    11901192  }
    1191   Free(&FragmentSearch.BondsPerSPList);
     1193  delete[](FragmentSearch.BondsPerSPList);
    11921194};
    11931195
     
    13941396
    13951397    // prepare the subset and call the generator
    1396     BondsList = Calloc<bond*>(FragmentSearch.BondsPerSPCount[0], "molecule::PowerSetGenerator: **BondsList");
     1398    bond* BondsList[FragmentSearch.BondsPerSPCount[0]];
     1399    for(int i=0;i<FragmentSearch.BondsPerSPCount[0];i++)
     1400      BondsList[i] = NULL;
    13971401    BondsList[0] = FragmentSearch.BondsPerSPList[0]->next;  // on SP level 0 there's only the root bond
    13981402
    13991403    SPFragmentGenerator(&FragmentSearch, 0, BondsList, FragmentSearch.BondsPerSPCount[0], Order);
    1400 
    1401     Free(&BondsList);
    14021404  } else {
    14031405    DoLog(0) && (Log() << Verbose(0) << "Not enough total number of edges to build " << Order << "-body fragments." << endl);
     
    15071509      }
    15081510    }
    1509     Free(&FragmentLowerOrdersList[RootNr]);
     1511    delete[](FragmentLowerOrdersList[RootNr]);
    15101512    RootNr++;
    15111513  }
    1512   Free(&FragmentLowerOrdersList);
     1514  delete[](FragmentLowerOrdersList);
    15131515};
    15141516
     
    15491551  // FragmentLowerOrdersList is a 2D-array of pointer to MoleculeListClass objects, one dimension represents the ANOVA expansion of a single order (i.e. 5)
    15501552  // with all needed lower orders that are subtracted, the other dimension is the BondOrder (i.e. from 1 to 5)
    1551   NumMoleculesOfOrder = Calloc<int>(UpgradeCount, "molecule::FragmentBOSSANOVA: *NumMoleculesOfOrder");
    1552   FragmentLowerOrdersList = Calloc<Graph**>(UpgradeCount, "molecule::FragmentBOSSANOVA: ***FragmentLowerOrdersList");
     1553  NumMoleculesOfOrder = new int[UpgradeCount];
     1554  FragmentLowerOrdersList = new Graph**[UpgradeCount];
     1555
     1556  for(int i=0;i<UpgradeCount;i++) {
     1557    NumMoleculesOfOrder[i] = 0;
     1558    FragmentLowerOrdersList[i] = NULL;
     1559  }
    15531560
    15541561  // initialise the fragments structure
     
    15561563  FragmentSearch.FragmentSet = new KeySet;
    15571564  FragmentSearch.Root = FindAtom(RootKeyNr);
    1558   FragmentSearch.ShortestPathList = Malloc<int>(AtomCount, "molecule::PowerSetGenerator: *ShortestPathList");
     1565  FragmentSearch.ShortestPathList = new int[AtomCount];
    15591566  for (int i=AtomCount;i--;) {
    15601567    FragmentSearch.ShortestPathList[i] = -1;
     
    15921599      // allocate memory for all lower level orders in this 1D-array of ptrs
    15931600      NumLevels = 1 << (Order-1); // (int)pow(2,Order);
    1594       FragmentLowerOrdersList[RootNr] = Calloc<Graph*>(NumLevels, "molecule::FragmentBOSSANOVA: **FragmentLowerOrdersList[]");
     1601      FragmentLowerOrdersList[RootNr] = new Graph*[NumLevels];
     1602      for (int i=0;i<NumLevels;i++)
     1603        FragmentLowerOrdersList[RootNr][i] = NULL;
    15951604
    15961605      // create top order where nothing is reduced
     
    16281637
    16291638  // cleanup FragmentSearch structure
    1630   Free(&FragmentSearch.ShortestPathList);
     1639  delete[](FragmentSearch.ShortestPathList);
    16311640  delete(FragmentSearch.FragmentSet);
    16321641
     
    16411650  CombineAllOrderListIntoOne(FragmentList, FragmentLowerOrdersList, RootStack, this);
    16421651  FreeAllOrdersList(FragmentLowerOrdersList, RootStack, this);
    1643   Free(&NumMoleculesOfOrder);
     1652  delete[](NumMoleculesOfOrder);
    16441653
    16451654  DoLog(0) && (Log() << Verbose(0) << "End of FragmentBOSSANOVA." << endl);
     
    16691678  DoLog(2) && (Log() << Verbose(2) << "Begin of ScanForPeriodicCorrection." << endl);
    16701679
    1671   ColorList = Calloc<enum Shading>(AtomCount, "molecule::ScanForPeriodicCorrection: *ColorList");
     1680  ColorList = new enum Shading[AtomCount];
     1681  for (int i=0;i<AtomCount;i++)
     1682    ColorList[i] = (enum Shading)0;
    16721683  while (flag) {
    16731684    // remove bonds that are beyond bonddistance
     
    17291740  // free allocated space from ReturnFullMatrixforSymmetric()
    17301741  delete(AtomStack);
    1731   Free(&ColorList);
    1732   Free(&matrix);
     1742  delete[](ColorList);
     1743  delete[](matrix);
    17331744  DoLog(2) && (Log() << Verbose(2) << "End of ScanForPeriodicCorrection." << endl);
    17341745};
Note: See TracChangeset for help on using the changeset viewer.