Changeset 7218f8 for src


Ignore:
Timestamp:
Nov 3, 2009, 12:37:55 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:
2aeefd
Parents:
fa649a
git-author:
Frederik Heber <heber@…> (11/03/09 08:41:45)
git-committer:
Frederik Heber <heber@…> (11/03/09 12:37:55)
Message:

Several memory bugfixes (thx valgrind).

Fixed Calloc:

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

Location:
src
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • src/builder.cpp

    rfa649a r7218f8  
    15741574                int *MinimumRingSize = new int[mol->AtomCount];
    15751575                atom ***ListOfLocalAtoms = NULL;
    1576                 int FragmentCounter = 0;
    15771576                class StackClass<bond *> *BackEdgeStack = NULL;
    15781577                class StackClass<bond *> *LocalBackEdgeStack = NULL;
     
    15801579                Subgraphs = mol->DepthFirstSearchAnalysis((ofstream *)&cout, BackEdgeStack);
    15811580                if (Subgraphs != NULL) {
    1582                   Subgraphs->next->FillBondStructureFromReference((ofstream *)&cout, mol, (FragmentCounter = 0), ListOfLocalAtoms, false);  // we want to keep the created ListOfLocalAtoms
     1581                  int FragmentCounter = 0;
    15831582                  while (Subgraphs->next != NULL) {
    15841583                    Subgraphs = Subgraphs->next;
     1584                    Subgraphs->FillBondStructureFromReference((ofstream *)&cout, mol, FragmentCounter, ListOfLocalAtoms, false);  // we want to keep the created ListOfLocalAtoms
    15851585                    LocalBackEdgeStack = new StackClass<bond *> (Subgraphs->Leaf->BondCount);
    1586                     Subgraphs->Leaf->PickLocalBackEdges((ofstream *)&cout, ListOfLocalAtoms[FragmentCounter++], BackEdgeStack, LocalBackEdgeStack);
    1587                     Subgraphs->Leaf->CyclicStructureAnalysis((ofstream *)&cout, BackEdgeStack, MinimumRingSize);
     1586                    Subgraphs->Leaf->PickLocalBackEdges((ofstream *)&cout, ListOfLocalAtoms[FragmentCounter], BackEdgeStack, LocalBackEdgeStack);
     1587                    Subgraphs->Leaf->CyclicStructureAnalysis((ofstream *)&cout, LocalBackEdgeStack, MinimumRingSize);
    15881588                    delete(LocalBackEdgeStack);
    15891589                    delete(Subgraphs->previous);
     1590                    FragmentCounter++;
    15901591                  }
    15911592                  delete(Subgraphs);
    15921593                  for (int i=0;i<FragmentCounter;i++)
    1593                     Free(&ListOfLocalAtoms[FragmentCounter]);
     1594                    Free(&ListOfLocalAtoms[i]);
    15941595                  Free(&ListOfLocalAtoms);
    15951596                }
     
    21152116  switch(j) {
    21162117    case 255:  // something went wrong
     2118    case 2:  // just for -f option
     2119    case 1:  // just for -v and -h options
    21172120      delete(molecules); // also free's all molecules contained
    21182121      delete(periode);
     2122      delete(configuration);
    21192123      cout << Verbose(0) <<  "Maximum of allocated memory: "
    21202124        << MemoryUsageObserver::getInstance()->getMaximumUsedMemory() << endl;
    21212125      cout << Verbose(0) <<  "Remaining non-freed memory: "
    21222126        << MemoryUsageObserver::getInstance()->getUsedMemorySize() << endl;
    2123      return j;
    2124       break;
    2125     case 1:  // just for -v and -h options
    2126       delete(molecules); // also free's all molecules contained
    2127       delete(periode);
    2128       cout << Verbose(0) <<  "Maximum of allocated memory: "
    2129         << MemoryUsageObserver::getInstance()->getMaximumUsedMemory() << endl;
    2130       cout << Verbose(0) <<  "Remaining non-freed memory: "
    2131         << MemoryUsageObserver::getInstance()->getUsedMemorySize() << endl;
    2132       return 0;
    2133       break;
    2134     case 2:  // just for -f option
    2135       delete(molecules); // also free's all molecules contained
    2136       delete(periode);
    2137       cout << Verbose(0) <<  "Maximum of allocated memory: "
    2138         << MemoryUsageObserver::getInstance()->getMaximumUsedMemory() << endl;
    2139       cout << Verbose(0) <<  "Remaining non-freed memory: "
    2140         << MemoryUsageObserver::getInstance()->getUsedMemorySize() << endl;
    2141       return 2;
    2142       break;
     2127      MemoryUsageObserver::getInstance()->purgeInstance();
     2128     return (j == 1 ? 0 : j);
    21432129    default:
    21442130      break;
     
    21552141      }
    21562142    }
     2143    mol->ActiveFlag = true;
    21572144    molecules->insert(mol);
    21582145  }
  • src/config.cpp

    rfa649a r7218f8  
    199199    Free(&ThermostatNames[j]);
    200200  Free(&ThermostatNames);
     201  if (BG != NULL)
     202    delete(BG);
    201203};
    202204
  • src/helpers.hpp

    rfa649a r7218f8  
    9898  }
    9999
    100   // allocat and fill
    101   LookupTable = Malloc<T*>(count, "CreateFatherLookupTable - **LookupTable");
     100  // allocate and fill
     101  LookupTable = Calloc<T*>(count, "CreateFatherLookupTable - **LookupTable");
    102102  if (LookupTable == NULL) {
    103103    cerr << "LookupTable memory allocation failed!" << endl;
  • src/memoryallocator.hpp

    rfa649a r7218f8  
    5555template <> char* Malloc<char>(size_t size, const char* output);
    5656
    57 /** Allocates a memory range using calloc().
     57/* Allocates a memory range using calloc().
    5858 * Prints the provided error message in case of a failure.
    5959 *
     
    6161 * \param failure message which is printed if the allocation fails
    6262 * \return pointer to the allocated memory range, will be NULL if a failure occurred
    63  */
     63*/
    6464template <typename X> X* Calloc(size_t size, const char* output)
    6565{
    6666  X* buffer = NULL;
    67   buffer = (X*) calloc(sizeof(X) * size, (size_t) 0);
     67  buffer = (X*) calloc(size, sizeof(X));
    6868
    6969  if (buffer != NULL) {
     
    7676  return buffer;
    7777};
     78
    7879
    7980/** Reallocates a memory range using realloc(). If the provided pointer to the old
  • src/memoryusageobserver.cpp

    rfa649a r7218f8  
    2323 */
    2424MemoryUsageObserver::~MemoryUsageObserver() {
    25   for (map<void*, size_t>::iterator current = memoryUsers.begin(); current != memoryUsers.end(); current++) {
     25  while (!memoryUsers.empty()) {
     26    map<void*, size_t>::iterator current = memoryUsers.begin();
     27    free(current->first);
    2628    memoryUsers.erase(current);
    2729  }
  • src/molecule.cpp

    rfa649a r7218f8  
    957957  if (result) {
    958958    *out << Verbose(5) << "Calculating distances" << endl;
    959     Distances = Malloc<double>(AtomCount, "molecule::IsEqualToWithinThreshold: Distances");
    960     OtherDistances = Malloc<double>(AtomCount, "molecule::IsEqualToWithinThreshold: OtherDistances");
     959    Distances = Calloc<double>(AtomCount, "molecule::IsEqualToWithinThreshold: Distances");
     960    OtherDistances = Calloc<double>(AtomCount, "molecule::IsEqualToWithinThreshold: OtherDistances");
    961961    SetIndexedArrayForEachAtomTo ( Distances, &atom::nr, &atom::DistanceSquaredToVector, (const Vector &)CenterOfGravity);
    962962    SetIndexedArrayForEachAtomTo ( OtherDistances, &atom::nr, &atom::DistanceSquaredToVector, (const Vector &)CenterOfGravity);
     
    964964    /// ... sort each list (using heapsort (o(N log N)) from GSL)
    965965    *out << Verbose(5) << "Sorting distances" << endl;
    966     PermMap = Malloc<size_t>(AtomCount, "molecule::IsEqualToWithinThreshold: *PermMap");
    967     OtherPermMap = Malloc<size_t>(AtomCount, "molecule::IsEqualToWithinThreshold: *OtherPermMap");
     966    PermMap = Calloc<size_t>(AtomCount, "molecule::IsEqualToWithinThreshold: *PermMap");
     967    OtherPermMap = Calloc<size_t>(AtomCount, "molecule::IsEqualToWithinThreshold: *OtherPermMap");
    968968    gsl_heapsort_index (PermMap, Distances, AtomCount, sizeof(double), CompareDoubles);
    969969    gsl_heapsort_index (OtherPermMap, OtherDistances, AtomCount, sizeof(double), CompareDoubles);
    970     PermutationMap = Malloc<int>(AtomCount, "molecule::IsEqualToWithinThreshold: *PermutationMap");
     970    PermutationMap = Calloc<int>(AtomCount, "molecule::IsEqualToWithinThreshold: *PermutationMap");
    971971    *out << Verbose(5) << "Combining Permutation Maps" << endl;
    972972    for(int i=AtomCount;i--;)
  • src/molecule_dynamics.cpp

    rfa649a r7218f8  
    193193{
    194194  stringstream zeile1, zeile2;
    195   int *DoubleList = Malloc<int>(AtomCount, "PrintPermutationMap: *DoubleList");
     195  int *DoubleList = Calloc<int>(AtomCount, "PrintPermutationMap: *DoubleList");
    196196  int doubles = 0;
    197   for (int i=0;i<AtomCount;i++)
    198     DoubleList[i] = 0;
    199197  zeile1 << "PermutationMap: ";
    200198  zeile2 << "                ";
     
    243241void CreateInitialLists(ofstream *out, molecule *mol, struct EvaluatePotential &Params)
    244242{
    245   for (int i=mol->AtomCount; i--;)
    246     Params.DoubleList[i] = 0;  // stores for how many atoms in startstep this atom is a target in endstep
    247 
    248243  atom *Walker = mol->start;
    249244  while (Walker->next != mol->end) {
     
    347342  double Potential, OldPotential, OlderPotential;
    348343  struct EvaluatePotential Params;
    349   Params.PermutationMap = Malloc<atom*>(AtomCount, "molecule::MinimiseConstrainedPotential: Params.**PermutationMap");
     344  Params.PermutationMap = Calloc<atom*>(AtomCount, "molecule::MinimiseConstrainedPotential: Params.**PermutationMap");
    350345  Params.DistanceList = Malloc<DistanceMap*>(AtomCount, "molecule::MinimiseConstrainedPotential: Params.**DistanceList");
    351346  Params.DistanceIterators = Malloc<DistanceMap::iterator>(AtomCount, "molecule::MinimiseConstrainedPotential: Params.*DistanceIterators");
    352   Params.DoubleList = Malloc<int>(AtomCount, "molecule::MinimiseConstrainedPotential: Params.*DoubleList");
     347  Params.DoubleList = Calloc<int>(AtomCount, "molecule::MinimiseConstrainedPotential: Params.*DoubleList");
    353348  Params.StepList = Malloc<DistanceMap::iterator>(AtomCount, "molecule::MinimiseConstrainedPotential: Params.*StepList");
    354349  int round;
  • src/molecule_fragmentation.cpp

    rfa649a r7218f8  
    123123  }
    124124
     125  Free(&filename);
    125126  return status;
    126127};
     
    574575  // ===== 2. perform a DFS analysis to gather info on cyclic structure and a list of disconnected subgraphs =====
    575576  Subgraphs = DepthFirstSearchAnalysis(out, BackEdgeStack);
    576   // fill the bond structure of the individually stored subgraphs
    577   Subgraphs->next->FillBondStructureFromReference(out, this, (FragmentCounter = 0), ListOfLocalAtoms, false);  // we want to keep the created ListOfLocalAtoms
     577
    578578  // analysis of the cycles (print rings, get minimum cycle length) for each subgraph
    579579  for(int i=AtomCount;i--;)
     
    583583  while (MolecularWalker->next != NULL) {
    584584    MolecularWalker = MolecularWalker->next;
     585    // fill the bond structure of the individually stored subgraphs
     586  MolecularWalker->FillBondStructureFromReference(out, this, FragmentCounter, ListOfLocalAtoms, false);  // we want to keep the created ListOfLocalAtoms
    585587    *out << Verbose(0) << "Analysing the cycles of subgraph " << MolecularWalker->Leaf << " with nr. " << FragmentCounter << "." << endl;
    586588    LocalBackEdgeStack = new StackClass<bond *> (MolecularWalker->Leaf->BondCount);
     
    599601    delete(LocalBackEdgeStack);
    600602  }
     603  delete(BackEdgeStack);
    601604
    602605  // ===== 3. if structure still valid, parse key set file and others =====
     
    663666  // ===== 8b. gather keyset lists (graphs) from all subgraphs and transform into MoleculeListClass =====
    664667  //if (FragmentationToDo) {    // we should always store the fragments again as coordination might have changed slightly without changing bond structure
    665     // allocate memory for the pointer array and transmorph graphs into full molecular fragments
    666     BondFragments = new MoleculeListClass();
    667     int k=0;
    668     for(Graph::iterator runner = TotalGraph.begin(); runner != TotalGraph.end(); runner++) {
    669       KeySet test = (*runner).first;
    670       *out << "Fragment No." << (*runner).second.first << " with TEFactor " << (*runner).second.second << "." << endl;
    671       BondFragments->insert(StoreFragmentFromKeySet(out, test, configuration));
    672       k++;
    673     }
    674     *out << k << "/" << BondFragments->ListOfMolecules.size() << " fragments generated from the keysets." << endl;
    675 
    676     // ===== 9. Save fragments' configuration and keyset files et al to disk ===
    677     if (BondFragments->ListOfMolecules.size() != 0) {
    678       // create the SortIndex from BFS labels to order in the config file
    679       CreateMappingLabelsToConfigSequence(out, SortIndex);
    680 
    681       *out << Verbose(1) << "Writing " << BondFragments->ListOfMolecules.size() << " possible bond fragmentation configs" << endl;
    682       if (BondFragments->OutputConfigForListOfFragments(out, configuration, SortIndex))
    683         *out << Verbose(1) << "All configs written." << endl;
    684       else
    685         *out << Verbose(1) << "Some config writing failed." << endl;
    686 
    687       // store force index reference file
    688       BondFragments->StoreForcesFile(out, configuration->configpath, SortIndex);
    689 
    690       // store keysets file
    691       StoreKeySetFile(out, TotalGraph, configuration->configpath);
    692 
    693       // store Adjacency file
    694       StoreAdjacencyToFile(out, configuration->configpath);
    695 
    696       // store Hydrogen saturation correction file
    697       BondFragments->AddHydrogenCorrection(out, configuration->configpath);
    698 
    699       // store adaptive orders into file
    700       StoreOrderAtSiteFile(out, configuration->configpath);
    701 
    702       // restore orbital and Stop values
    703       CalculateOrbitals(*configuration);
    704 
    705       // free memory for bond part
    706       *out << Verbose(1) << "Freeing bond memory" << endl;
    707       delete(FragmentList); // remove bond molecule from memory
    708       Free(&SortIndex);
    709     } else
    710       *out << Verbose(1) << "FragmentList is zero on return, splitting failed." << endl;
    711   //} else
    712   //  *out << Verbose(1) << "No fragments to store." << endl;
     668  // allocate memory for the pointer array and transmorph graphs into full molecular fragments
     669  BondFragments = new MoleculeListClass();
     670  int k=0;
     671  for(Graph::iterator runner = TotalGraph.begin(); runner != TotalGraph.end(); runner++) {
     672    KeySet test = (*runner).first;
     673    *out << "Fragment No." << (*runner).second.first << " with TEFactor " << (*runner).second.second << "." << endl;
     674    BondFragments->insert(StoreFragmentFromKeySet(out, test, configuration));
     675    k++;
     676  }
     677  *out << k << "/" << BondFragments->ListOfMolecules.size() << " fragments generated from the keysets." << endl;
     678
     679  // ===== 9. Save fragments' configuration and keyset files et al to disk ===
     680  if (BondFragments->ListOfMolecules.size() != 0) {
     681    // create the SortIndex from BFS labels to order in the config file
     682    CreateMappingLabelsToConfigSequence(out, SortIndex);
     683
     684    *out << Verbose(1) << "Writing " << BondFragments->ListOfMolecules.size() << " possible bond fragmentation configs" << endl;
     685    if (BondFragments->OutputConfigForListOfFragments(out, configuration, SortIndex))
     686      *out << Verbose(1) << "All configs written." << endl;
     687    else
     688      *out << Verbose(1) << "Some config writing failed." << endl;
     689
     690    // store force index reference file
     691    BondFragments->StoreForcesFile(out, configuration->configpath, SortIndex);
     692
     693    // store keysets file
     694    StoreKeySetFile(out, TotalGraph, configuration->configpath);
     695
     696    // store Adjacency file
     697    StoreAdjacencyToFile(out, configuration->configpath);
     698
     699    // store Hydrogen saturation correction file
     700    BondFragments->AddHydrogenCorrection(out, configuration->configpath);
     701
     702    // store adaptive orders into file
     703    StoreOrderAtSiteFile(out, configuration->configpath);
     704
     705    // restore orbital and Stop values
     706    CalculateOrbitals(*configuration);
     707
     708    // free memory for bond part
     709    *out << Verbose(1) << "Freeing bond memory" << endl;
     710    delete(FragmentList); // remove bond molecule from memory
     711    Free(&SortIndex);
     712  } else {
     713    *out << Verbose(1) << "FragmentList is zero on return, splitting failed." << endl;
     714  }
     715  delete(BondFragments);
    713716  *out << Verbose(0) << "End of bond fragmentation." << endl;
    714717
     
    751754bool molecule::ParseOrderAtSiteFromFile(ofstream *out, char *path)
    752755{
    753   unsigned char *OrderArray = Malloc<unsigned char>(AtomCount, "molecule::ParseOrderAtSiteFromFile - *OrderArray");
    754   bool *MaxArray = Malloc<bool>(AtomCount, "molecule::ParseOrderAtSiteFromFile - *MaxArray");
     756  unsigned char *OrderArray = Calloc<unsigned char>(AtomCount, "molecule::ParseOrderAtSiteFromFile - *OrderArray");
     757  bool *MaxArray = Calloc<bool>(AtomCount, "molecule::ParseOrderAtSiteFromFile - *MaxArray");
    755758  bool status;
    756759  int AtomNr, value;
     
    759762
    760763  *out << Verbose(1) << "Begin of ParseOrderAtSiteFromFile" << endl;
    761   for(int i=AtomCount;i--;)
    762     OrderArray[i] = 0;
    763764  line << path << "/" << FRAGMENTPREFIX << ORDERATSITEFILE;
    764765  file.open(line.str().c_str());
    765766  if (file != NULL) {
    766     for (int i=AtomCount;i--;) { // initialise with 0
    767       OrderArray[i] = 0;
    768       MaxArray[i] = 0;
    769     }
    770767    while (!file.eof()) { // parse from file
    771768      AtomNr = -1;
     
    830827 * \param *Leaf fragment molecule
    831828 * \param &Leaflet pointer to KeySet structure
    832  * \param **SonList list which atom of \a *Leaf is a son of which atom in \a *mol
     829 * \param **SonList calloc'd list which atom of \a *Leaf is a son of which atom in \a *mol
    833830 * \return number of atoms in fragment
    834831 */
     
    840837  for(int i=NDIM*2;i--;)
    841838    Leaf->cell_size[i] = mol->cell_size[i];
    842 
    843   // initialise SonList (indicates when we need to replace a bond with hydrogen instead)
    844   for(int i=mol->AtomCount;i--;)
    845     SonList[i] = NULL;
    846839
    847840  // first create the minimal set of atoms from the KeySet
     
    924917molecule * molecule::StoreFragmentFromKeySet(ofstream *out, KeySet &Leaflet, bool IsAngstroem)
    925918{
    926   atom **SonList = Malloc<atom*>(AtomCount, "molecule::StoreFragmentFromStack: **SonList");
     919  atom **SonList = Calloc<atom*>(AtomCount, "molecule::StoreFragmentFromStack: **SonList");
    927920  molecule *Leaf = new molecule(elemente);
    928921
     
    13891382
    13901383    // prepare the subset and call the generator
    1391     BondsList = Malloc<bond*>(FragmentSearch.BondsPerSPCount[0], "molecule::PowerSetGenerator: **BondsList");
     1384    BondsList = Calloc<bond*>(FragmentSearch.BondsPerSPCount[0], "molecule::PowerSetGenerator: **BondsList");
    13921385    BondsList[0] = FragmentSearch.BondsPerSPList[0]->next;  // on SP level 0 there's only the root bond
    13931386
     
    15441537  // FragmentLowerOrdersList is a 2D-array of pointer to MoleculeListClass objects, one dimension represents the ANOVA expansion of a single order (i.e. 5)
    15451538  // with all needed lower orders that are subtracted, the other dimension is the BondOrder (i.e. from 1 to 5)
    1546   NumMoleculesOfOrder = Malloc<int>(UpgradeCount, "molecule::FragmentBOSSANOVA: *NumMoleculesOfOrder");
    1547   FragmentLowerOrdersList = Malloc<Graph**>(UpgradeCount, "molecule::FragmentBOSSANOVA: ***FragmentLowerOrdersList");
     1539  NumMoleculesOfOrder = Calloc<int>(UpgradeCount, "molecule::FragmentBOSSANOVA: *NumMoleculesOfOrder");
     1540  FragmentLowerOrdersList = Calloc<Graph**>(UpgradeCount, "molecule::FragmentBOSSANOVA: ***FragmentLowerOrdersList");
    15481541
    15491542  // initialise the fragments structure
    1550   FragmentSearch.ShortestPathList = Malloc<int>(AtomCount, "molecule::PowerSetGenerator: *ShortestPathList");
    15511543  FragmentSearch.FragmentCounter = 0;
    15521544  FragmentSearch.FragmentSet = new KeySet;
    15531545  FragmentSearch.Root = FindAtom(RootKeyNr);
     1546  FragmentSearch.ShortestPathList = Malloc<int>(AtomCount, "molecule::PowerSetGenerator: *ShortestPathList");
    15541547  for (int i=AtomCount;i--;) {
    15551548    FragmentSearch.ShortestPathList[i] = -1;
     
    15871580      // allocate memory for all lower level orders in this 1D-array of ptrs
    15881581      NumLevels = 1 << (Order-1); // (int)pow(2,Order);
    1589       FragmentLowerOrdersList[RootNr] = Malloc<Graph*>(NumLevels, "molecule::FragmentBOSSANOVA: **FragmentLowerOrdersList[]");
    1590       for (int i=0;i<NumLevels;i++)
    1591         FragmentLowerOrdersList[RootNr][i] = NULL;
     1582      FragmentLowerOrdersList[RootNr] = Calloc<Graph*>(NumLevels, "molecule::FragmentBOSSANOVA: **FragmentLowerOrdersList[]");
    15921583
    15931584      // create top order where nothing is reduced
     
    16651656  *out << Verbose(2) << "Begin of ScanForPeriodicCorrection." << endl;
    16661657
    1667   ColorList = Malloc<enum Shading>(AtomCount, "molecule::ScanForPeriodicCorrection: *ColorList");
     1658  ColorList = Calloc<enum Shading>(AtomCount, "molecule::ScanForPeriodicCorrection: *ColorList");
    16681659  while (flag) {
    16691660    // remove bonds that are beyond bonddistance
  • src/molecule_graph.cpp

    rfa649a r7218f8  
    126126
    127127    // create a list to map Tesselpoint::nr to atom *
    128     AtomMap = Malloc<atom *> (AtomCount, "molecule::CreateAdjacencyList - **AtomCount");
     128    AtomMap = Calloc<atom *> (AtomCount, "molecule::CreateAdjacencyList - **AtomCount");
    129129    Walker = start;
    130130    while (Walker->next != end) {
     
    437437 * \param *out output stream for debugging
    438438 * \param &DFS accounting structure to allocate
    439  * \param AtomCount number of nodes in graph
    440  * \param BondCount number of edges in graph
    441  */
    442 void DepthFirstSearchAnalysis_Init(ofstream *out, struct DFSAccounting &DFS, int AtomCount, int BondCount)
    443 {
    444   DFS.AtomStack = new StackClass<atom *> (AtomCount);
     439 * \param *mol molecule with AtomCount, BondCount and all atoms
     440 */
     441void DepthFirstSearchAnalysis_Init(ofstream *out, struct DFSAccounting &DFS, const molecule * const mol)
     442{
     443  DFS.AtomStack = new StackClass<atom *> (mol->AtomCount);
    445444  DFS.CurrentGraphNr = 0;
    446445  DFS.ComponentNumber = 0;
    447446  DFS.BackStepping = false;
     447  mol->ResetAllBondsToUnused();
     448  mol->SetAtomValueToValue(-1, &atom::GraphNr);
     449  mol->ActOnAllAtoms(&atom::InitComponentNr);
     450  DFS.BackEdgeStack->ClearStack();
    448451}
    449452;
     
    456459{
    457460  delete (DFS.AtomStack);
     461  // delete (DFS.BackEdgeStack); // DON'T free, see DepthFirstSearchAnalysis(), is returned as allocated
    458462}
    459463;
     
    479483
    480484  *out << Verbose(0) << "Begin of DepthFirstSearchAnalysis" << endl;
    481   DepthFirstSearchAnalysis_Init(out, DFS, AtomCount, BondCount);
     485  DepthFirstSearchAnalysis_Init(out, DFS, this);
     486
    482487  DFS.Root = start->next;
    483 
    484   ResetAllBondsToUnused();
    485   SetAtomValueToValue(-1, &atom::GraphNr);
    486   ActOnAllAtoms(&atom::InitComponentNr);
    487   DFS.BackEdgeStack->ClearStack();
    488488  while (DFS.Root != end) { // if there any atoms at all
    489     // (1) mark all edges unused, empty stack, set atom->GraphNr = 0 for all
     489    // (1) mark all edges unused, empty stack, set atom->GraphNr = -1 for all
    490490    DFS.AtomStack->ClearStack();
    491491
     
    602602{
    603603  BFS.AtomCount = AtomCount;
    604   BFS.PredecessorList = Malloc<atom*> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: **PredecessorList");
     604  BFS.PredecessorList = Calloc<atom*> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: **PredecessorList");
    605605  BFS.ShortestPathList = Malloc<int> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: *ShortestPathList");
    606   BFS.ColorList = Malloc<enum Shading> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: *ColorList");
     606  BFS.ColorList = Calloc<enum Shading> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: *ColorList");
    607607  BFS.BFSStack = new StackClass<atom *> (AtomCount);
    608608
    609   for (int i = AtomCount; i--;) {
    610     BFS.PredecessorList[i] = NULL;
     609  for (int i = AtomCount; i--;)
    611610    BFS.ShortestPathList[i] = -1;
    612     BFS.ColorList[i] = white;
    613   }
    614611};
    615612
     
    1002999
    10031000  // allocate storage structure
    1004   CurrentBonds = Malloc<int> (8, "molecule::CheckAdjacencyFileAgainstMolecule - CurrentBonds"); // contains parsed bonds of current atom
     1001  CurrentBonds = Calloc<int> (8, "molecule::CheckAdjacencyFileAgainstMolecule - CurrentBonds"); // contains parsed bonds of current atom
    10051002  return true;
    10061003}
     
    11371134  BFS.AtomCount = AtomCount;
    11381135  BFS.BondOrder = BondOrder;
    1139   BFS.PredecessorList = Malloc<atom*> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: **PredecessorList");
    1140   BFS.ShortestPathList = Malloc<int> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: *ShortestPathList");
     1136  BFS.PredecessorList = Calloc<atom*> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: **PredecessorList");
     1137  BFS.ShortestPathList = Calloc<int> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: *ShortestPathList");
    11411138  BFS.ColorList = Malloc<enum Shading> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: *ColorList");
    11421139  BFS.BFSStack = new StackClass<atom *> (AtomCount);
     
    11481145  // initialise each vertex as white with no predecessor, empty queue, color Root lightgray
    11491146  for (int i = AtomCount; i--;) {
    1150     BFS.PredecessorList[i] = NULL;
    11511147    BFS.ShortestPathList[i] = -1;
    11521148    if ((AddedAtomList != NULL) && (AddedAtomList[i] != NULL)) // mark already present atoms (i.e. Root and maybe others) as visited
     
    11551151      BFS.ColorList[i] = white;
    11561152  }
    1157   BFS.ShortestPathList[Root->nr] = 0;
     1153  //BFS.ShortestPathList[Root->nr] = 0; //is set due to Calloc()
    11581154}
    11591155;
     
    13021298{
    13031299  // reset parent list
    1304   ParentList = Malloc<atom*> (AtomCount, "molecule::BuildInducedSubgraph_Init: **ParentList");
     1300  ParentList = Calloc<atom*> (AtomCount, "molecule::BuildInducedSubgraph_Init: **ParentList");
    13051301  *out << Verbose(3) << "Resetting ParentList." << endl;
    1306   for (int i = AtomCount; i--;)
    1307     ParentList[i] = NULL;
    13081302}
    13091303;
  • src/moleculelist.cpp

    rfa649a r7218f8  
    422422
    423423  // 0b. allocate memory for constants
    424   FitConstant = Malloc<double**>(3, "MoleculeListClass::AddHydrogenCorrection: ***FitConstant");
     424  FitConstant = Calloc<double**>(3, "MoleculeListClass::AddHydrogenCorrection: ***FitConstant");
    425425  for (int k = 0; k < 3; k++) {
    426     FitConstant[k] = Malloc<double*>(a, "MoleculeListClass::AddHydrogenCorrection: **FitConstant[]");
     426    FitConstant[k] = Calloc<double*>(a, "MoleculeListClass::AddHydrogenCorrection: **FitConstant[]");
    427427    for (int i = a; i--;) {
    428       FitConstant[k][i] = Malloc<double>(b, "MoleculeListClass::AddHydrogenCorrection: *FitConstant[][]");
     428      FitConstant[k][i] = Calloc<double>(b, "MoleculeListClass::AddHydrogenCorrection: *FitConstant[][]");
    429429    }
    430430  }
     
    471471
    472472  // 0d. allocate final correction matrix
    473   correction = Malloc<double*>(a, "MoleculeListClass::AddHydrogenCorrection: **correction");
     473  correction = Calloc<double*>(a, "MoleculeListClass::AddHydrogenCorrection: **correction");
    474474  for (int i = a; i--;)
    475     correction[i] = Malloc<double>(b, "MoleculeListClass::AddHydrogenCorrection: *correction[]");
     475    correction[i] = Calloc<double>(b, "MoleculeListClass::AddHydrogenCorrection: *correction[]");
    476476
    477477  // 1a. go through every molecule in the list
     
    548548  output.close();
    549549  // 6. free memory of parsed matrices
    550   FitConstant = Malloc<double**>(a, "MoleculeListClass::AddHydrogenCorrection: ***FitConstant");
    551550  for (int k = 0; k < 3; k++) {
    552     FitConstant[k] = Malloc<double*>(a, "MoleculeListClass::AddHydrogenCorrection: **FitConstant[]");
    553551    for (int i = a; i--;) {
    554       FitConstant[k][i] = Malloc<double>(b, "MoleculeListClass::AddHydrogenCorrection: *FitConstant[][]");
    555     }
    556   }
     552      Free(&FitConstant[k][i]);
     553    }
     554    Free(&FitConstant[k]);
     555  }
     556  Free(&FitConstant);
    557557  cout << "done." << endl;
    558558  return true;
     
    712712    //outputFragment.close();
    713713    //outputFragment.clear();
    714     delete (FragmentNumber);
    715     //Free(&FragmentNumber);
     714    Free(&FragmentNumber);
    716715  }
    717716  cout << " done." << endl;
     
    848847      }
    849848    }
    850     FragmentCounter++;
    851     if (next != NULL)
    852       status = next->FillBondStructureFromReference(out, reference, FragmentCounter, ListOfLocalAtoms);
    853     FragmentCounter--;
     849//    FragmentCounter++;
     850//    if (next != NULL)
     851//      status = next->FillBondStructureFromReference(out, reference, FragmentCounter, ListOfLocalAtoms);
     852//    FragmentCounter--;
    854853  }
    855854
     
    860859      Free(&ListOfLocalAtoms);
    861860  }
    862   FragmentCounter--;
    863861  *out << Verbose(1) << "End of FillBondStructureFromReference." << endl;
    864862  return status;
     
    907905
    908906/** Fills a lookup list of father's Atom::nr -> atom for each subgraph.
    909  * \param *out output stream fro debugging
     907 * \param *out output stream from debugging
    910908 * \param ***ListOfLocalAtoms Lookup table for each subgraph and index of each atom in global molecule, may be NULL on start, then it is filled
    911909 * \param FragmentCounter counts the fragments as we move along the list
    912910 * \param GlobalAtomCount number of atoms in the complete molecule
    913911 * \param &FreeList true - ***ListOfLocalAtoms is free'd before return, false - it is not
    914  * \return true - succes, false - failure
     912 * \return true - success, false - failure
    915913 */
    916914bool MoleculeLeafClass::FillListOfLocalAtoms(ofstream *out, atom ***&ListOfLocalAtoms, const int FragmentCounter, const int GlobalAtomCount, bool &FreeList)
     
    921919  if (ListOfLocalAtoms == NULL) { // allocated initial pointer
    922920    // allocate and set each field to NULL
    923     ListOfLocalAtoms = Malloc<atom**>(Counter, "MoleculeLeafClass::FillBondStructureFromReference - ***ListOfLocalAtoms");
     921    ListOfLocalAtoms = Calloc<atom**>(Counter, "MoleculeLeafClass::FillListOfLocalAtoms - ***ListOfLocalAtoms");
    924922    if (ListOfLocalAtoms != NULL) {
    925       for (int i = Counter; i--;)
    926         ListOfLocalAtoms[i] = NULL;
    927923      FreeList = FreeList && true;
    928924    } else
     
    965961  if (FragmentList == NULL) {
    966962    KeySetCounter = Count();
    967     FragmentList = Malloc<Graph*>(KeySetCounter, "MoleculeLeafClass::AssignKeySetsToFragment - **FragmentList");
    968     for (int i = KeySetCounter; i--;)
    969       FragmentList[i] = NULL;
     963    FragmentList = Calloc<Graph*>(KeySetCounter, "MoleculeLeafClass::AssignKeySetsToFragment - **FragmentList");
    970964    KeySetCounter = 0;
    971965  }
  • src/stackclass.hpp

    rfa649a r7218f8  
    4848/** Constructor of class StackClass.
    4949 */
    50 template <typename T> StackClass<T>::StackClass(int dimension) : EntryCount(dimension), CurrentLastEntry(0), CurrentFirstEntry(0), NextFreeField(0)
    51 {
    52   StackList = Malloc<T>(EntryCount, "StackClass::StackClass: **StackList");
     50template <typename T> StackClass<T>::StackClass(int dimension) : StackList(NULL), EntryCount(dimension), CurrentLastEntry(0), CurrentFirstEntry(0), NextFreeField(0)
     51{
     52  StackList = Calloc<T>(EntryCount, "StackClass::StackClass: **StackList");
    5353};
    5454
  • src/unittests/memoryallocatorunittest.cpp

    rfa649a r7218f8  
    2828void MemoryAllocatorTest::tearDown()
    2929{
     30  MemoryUsageObserver::getInstance()->purgeInstance();
    3031};
    3132
     
    4950
    5051  char** buffer4 = NULL;
    51   buffer4 = Malloc<char*>(1, "");
     52  buffer4 = Malloc<char*>(10, "");
     53  for (int i=0;i<10;i++)
     54    buffer4[i] = NULL;
    5255  Free(&buffer4);
    5356};
     
    5962{
    6063  int* buffer1 = NULL;
    61   buffer1 = Calloc<int>(1, "");
     64  buffer1 = Calloc<int>(10, "");
    6265  Free(&buffer1);
    6366
    6467  long* buffer2 = NULL;
    65   buffer2 = Calloc<long>(1, "");
     68  buffer2 = Calloc<long>(10, "");
    6669  Free(&buffer2);
    6770
    68   char* buffer3 = NULL;
    69   buffer3 = Calloc<char>(1, "");
     71  char** buffer3 = NULL;
     72  buffer3 = Calloc<char *>(10, "");
     73  for (int i=0;i<10;i++)
     74    buffer3[i] = NULL;
    7075  Free(&buffer3);
    7176};
Note: See TracChangeset for help on using the changeset viewer.