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_graph.cpp

    r87b597 r920c70  
    143143    // create a list to map Tesselpoint::nr to atom *
    144144    DoLog(2) && (Log() << Verbose(2) << "Creating TesselPoint to atom map ... " << endl);
    145     AtomMap = Calloc<atom *> (AtomCount, "molecule::CreateAdjacencyList - **AtomCount");
     145    AtomMap = new atom *[AtomCount];
     146    for (int i=0;i<AtomCount;i++)
     147      AtomMap[i] = NULL;
    146148    Walker = start;
    147149    while (Walker->next != end) {
     
    194196          }
    195197        }
    196     Free(&AtomMap);
     198    delete[](AtomMap);
    197199    delete (LC);
    198200    DoLog(1) && (Log() << Verbose(1) << "I detected " << BondCount << " bonds in the molecule with distance " << BondDistance << "." << endl);
     
    630632{
    631633  BFS.AtomCount = AtomCount;
    632   BFS.PredecessorList = Calloc<atom*> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: **PredecessorList");
    633   BFS.ShortestPathList = Malloc<int> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: *ShortestPathList");
    634   BFS.ColorList = Calloc<enum Shading> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: *ColorList");
     634  BFS.PredecessorList = new atom*[AtomCount];
     635  BFS.ShortestPathList = new int[AtomCount];
     636  BFS.ColorList = new enum Shading[AtomCount];
    635637  BFS.BFSStack = new StackClass<atom *> (AtomCount);
    636638
    637   for (int i = AtomCount; i--;)
     639  for (int i = AtomCount; i--;) {
    638640    BFS.ShortestPathList[i] = -1;
     641    BFS.PredecessorList[i] = 0;
     642  }
    639643};
    640644
     
    645649void FinalizeBFSAccounting(struct BFSAccounting &BFS)
    646650{
    647   Free(&BFS.PredecessorList);
    648   Free(&BFS.ShortestPathList);
    649   Free(&BFS.ColorList);
     651  delete[](BFS.PredecessorList);
     652  delete[](BFS.ShortestPathList);
     653  delete[](BFS.ColorList);
    650654  delete (BFS.BFSStack);
    651655  BFS.AtomCount = 0;
     
    10671071
    10681072  // allocate storage structure
    1069   CurrentBonds = Calloc<int> (8, "molecule::CheckAdjacencyFileAgainstMolecule - CurrentBonds"); // contains parsed bonds of current atom
     1073  CurrentBonds = new int[8]; // contains parsed bonds of current atom
     1074  for(int i=0;i<8;i++)
     1075    CurrentBonds[i] = 0;
    10701076  return true;
    10711077}
     
    10761082  File.close();
    10771083  File.clear();
    1078   Free(&CurrentBonds);
     1084  delete[](CurrentBonds);
    10791085}
    10801086;
     
    11201126  bool status = true;
    11211127  atom *Walker = NULL;
    1122   char *buffer = NULL;
    11231128  int *CurrentBonds = NULL;
    11241129  int NonMatchNumber = 0; // will number of atoms with differing bond structure
     
    11301135  }
    11311136
    1132   buffer = Malloc<char> (MAXSTRINGSIZE, "molecule::CheckAdjacencyFileAgainstMolecule: *buffer");
     1137  char buffer[MAXSTRINGSIZE];
    11331138  // Parse the file line by line and count the bonds
    11341139  while (!File.eof()) {
     
    11481153    }
    11491154  }
    1150   Free(&buffer);
    11511155  CheckAdjacencyFileAgainstMolecule_Finalize(File, CurrentBonds);
    11521156
     
    12021206  BFS.AtomCount = AtomCount;
    12031207  BFS.BondOrder = BondOrder;
    1204   BFS.PredecessorList = Calloc<atom*> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: **PredecessorList");
    1205   BFS.ShortestPathList = Calloc<int> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: *ShortestPathList");
    1206   BFS.ColorList = Malloc<enum Shading> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: *ColorList");
     1208  BFS.PredecessorList = new atom*[AtomCount];
     1209  BFS.ShortestPathList = new int[AtomCount];
     1210  BFS.ColorList = new enum Shading[AtomCount];
    12071211  BFS.BFSStack = new StackClass<atom *> (AtomCount);
    12081212
     
    12131217  // initialise each vertex as white with no predecessor, empty queue, color Root lightgray
    12141218  for (int i = AtomCount; i--;) {
     1219    BFS.PredecessorList[i] = NULL;
    12151220    BFS.ShortestPathList[i] = -1;
    12161221    if ((AddedAtomList != NULL) && (AddedAtomList[i] != NULL)) // mark already present atoms (i.e. Root and maybe others) as visited
     
    12191224      BFS.ColorList[i] = white;
    12201225  }
    1221   //BFS.ShortestPathList[Root->nr] = 0; //is set due to Calloc()
     1226  //BFS.ShortestPathList[Root->nr] = 0; // done by Calloc
    12221227}
    12231228;
     
    12251230void BreadthFirstSearchAdd_Free(struct BFSAccounting &BFS)
    12261231{
    1227   Free(&BFS.PredecessorList);
    1228   Free(&BFS.ShortestPathList);
    1229   Free(&BFS.ColorList);
     1232  delete[](BFS.PredecessorList);
     1233  delete[](BFS.ShortestPathList);
     1234  delete[](BFS.ColorList);
    12301235  delete (BFS.BFSStack);
    12311236  BFS.AtomCount = 0;
     
    13661371{
    13671372  // reset parent list
    1368   ParentList = Calloc<atom*> (AtomCount, "molecule::BuildInducedSubgraph_Init: **ParentList");
     1373  ParentList = new atom*[AtomCount];
     1374  for (int i=0;i<AtomCount;i++)
     1375    ParentList[i] = NULL;
    13691376  DoLog(3) && (Log() << Verbose(3) << "Resetting ParentList." << endl);
    13701377}
     
    13881395void BuildInducedSubgraph_Finalize(atom **&ParentList)
    13891396{
    1390   Free(&ParentList);
     1397  delete[](ParentList);
    13911398}
    13921399;
Note: See TracChangeset for help on using the changeset viewer.