Changeset 920c70 for src/config.cpp


Ignore:
Timestamp:
May 31, 2010, 1:09:58 PM (16 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, Candidate_v1.7.0, 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/config.cpp

    r87b597 r920c70  
    9393    return;
    9494  } else
    95     buffer = Malloc<char*>(NoLines, "ConfigFileBuffer::ConfigFileBuffer: **buffer");
     95    buffer = new char *[NoLines];
    9696
    9797  // scan each line and put into buffer
     
    9999  int i;
    100100  do {
    101     buffer[lines] = Malloc<char>(MAXSTRINGSIZE, "ConfigFileBuffer::ConfigFileBuffer: *buffer[]");
     101    buffer[lines] = new char[MAXSTRINGSIZE];
    102102    file->getline(buffer[lines], MAXSTRINGSIZE-1);
    103103    i = strlen(buffer[lines]);
     
    119119{
    120120  for(int i=0;i<NoLines;++i)
    121     Free(&buffer[i]);
    122   Free(&buffer);
    123   Free(&LineMapping);
     121    delete[](buffer[i]);
     122  delete[](buffer);
     123  delete[](LineMapping);
    124124}
    125125
     
    129129void ConfigFileBuffer::InitMapping()
    130130{
    131   LineMapping = Malloc<int>(NoLines, "ConfigFileBuffer::InitMapping: *LineMapping");
     131  LineMapping = new int[NoLines];
    132132  for (int i=0;i<NoLines;i++)
    133133    LineMapping[i] = i;
     
    179179    MaxLevel(5), RiemannTensor(0), LevRFactor(0), RiemannLevel(0), Lev0Factor(2), RTActualUse(0), AddPsis(0), RCut(20.), StructOpt(0), IsAngstroem(1), RelativeCoord(0),
    180180    MaxTypes(0) {
    181   mainname = Malloc<char>(MAXSTRINGSIZE,"config constructor: mainname");
    182   defaultpath = Malloc<char>(MAXSTRINGSIZE,"config constructor: defaultpath");
    183   pseudopotpath = Malloc<char>(MAXSTRINGSIZE,"config constructor: pseudopotpath");
    184   databasepath = Malloc<char>(MAXSTRINGSIZE,"config constructor: databasepath");
    185   configpath = Malloc<char>(MAXSTRINGSIZE,"config constructor: configpath");
    186   configname = Malloc<char>(MAXSTRINGSIZE,"config constructor: configname");
     181  mainname = new char[MAXSTRINGSIZE];
     182  defaultpath = new char[MAXSTRINGSIZE];
     183  pseudopotpath = new char[MAXSTRINGSIZE];
     184  databasepath = new char[MAXSTRINGSIZE];
     185  configpath = new char[MAXSTRINGSIZE];
     186  configname = new char[MAXSTRINGSIZE];
    187187  strcpy(mainname,"pcp");
    188188  strcpy(defaultpath,"not specified");
     
    199199config::~config()
    200200{
    201   Free(&mainname);
    202   Free(&defaultpath);
    203   Free(&pseudopotpath);
    204   Free(&databasepath);
    205   Free(&configpath);
    206   Free(&configname);
    207   Free(&ThermostatImplemented);
     201  delete[](mainname);
     202  delete[](defaultpath);
     203  delete[](pseudopotpath);
     204  delete[](databasepath);
     205  delete[](configpath);
     206  delete[](configname);
     207  delete[](ThermostatImplemented);
    208208  for (int j=0;j<MaxThermostats;j++)
    209     Free(&ThermostatNames[j]);
    210   Free(&ThermostatNames);
     209    delete[](ThermostatNames[j]);
     210  delete[](ThermostatNames);
    211211
    212212  if (BG != NULL)
     
    218218void config::InitThermostats()
    219219{
    220   ThermostatImplemented = Malloc<int>(MaxThermostats, "config constructor: *ThermostatImplemented");
    221   ThermostatNames = Malloc<char*>(MaxThermostats, "config constructor: *ThermostatNames");
     220  ThermostatImplemented = new int[MaxThermostats];
     221  ThermostatNames = new char *[MaxThermostats];
    222222  for (int j=0;j<MaxThermostats;j++)
    223     ThermostatNames[j] = Malloc<char>(12, "config constructor: ThermostatNames[]");
     223    ThermostatNames[j] = new char[12];
    224224
    225225  strcpy(ThermostatNames[0],"None");
     
    242242void config::ParseThermostats(class ConfigFileBuffer * const fb)
    243243{
    244   char * const thermo = Malloc<char>(12, "IonsInitRead: thermo");
     244  char * const thermo = new char[12];
    245245  const int verbose = 0;
    246246
     
    309309    Thermostat = None;
    310310  }
    311   Free(thermo);
     311  delete[](thermo);
    312312};
    313313
     
    15621562  for (MoleculeList::const_iterator Runner = MolList->ListOfMolecules.begin(); Runner != MolList->ListOfMolecules.end(); Runner++) {
    15631563    Walker = (*Runner)->start;
    1564     int *elementNo = Calloc<int>(MAX_ELEMENTS, "config::SavePDB - elementNo");
     1564    int *elementNo = new int[MAX_ELEMENTS];
     1565    for (int i=0;i<MAX_ELEMENTS;i++)
     1566      elementNo[i] = 0;
    15651567    AtomNo = 0;
    15661568    while (Walker->next != (*Runner)->end) {
     
    15851587      AtomNo++;
    15861588    }
    1587     Free(&elementNo);
     1589    delete[](elementNo);
    15881590    MolNo++;
    15891591  }
     
    16041606  FILE *f = NULL;
    16051607
    1606   int *elementNo = Calloc<int>(MAX_ELEMENTS, "config::SavePDB - elementNo");
     1608  int *elementNo = new int[MAX_ELEMENTS];
     1609  for (int i=0;i<MAX_ELEMENTS;i++)
     1610    elementNo[i] = 0;
    16071611  char name[MAXSTRINGSIZE];
    16081612  strncpy(name, filename, MAXSTRINGSIZE-1);
     
    16111615  if (f == NULL) {
    16121616    DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open pdb output file:" << name << endl);
    1613     Free(&elementNo);
     1617    delete[](elementNo);
    16141618    return false;
    16151619  }
     
    16401644  }
    16411645  fclose(f);
    1642   Free(&elementNo);
     1646  delete[](elementNo);
    16431647
    16441648  return true;
     
    17341738
    17351739  // create global to local id map
    1736   int **LocalNotoGlobalNoMap = Calloc<int *>(MolList->ListOfMolecules.size(), "config::SaveTREMOLO - **LocalNotoGlobalNoMap");
     1740  int **LocalNotoGlobalNoMap = new int *[MolList->ListOfMolecules.size()];
     1741  for (int i=0;i<MolList->ListOfMolecules.size();i++)
     1742    LocalNotoGlobalNoMap[i] = NULL;
    17371743  {
    17381744    int MolCounter = 0;
    17391745    int AtomNo = 0;
    17401746    for (MoleculeList::const_iterator MolWalker = MolList->ListOfMolecules.begin(); MolWalker != MolList->ListOfMolecules.end(); MolWalker++) {
    1741       LocalNotoGlobalNoMap[MolCounter] = Calloc<int>(MolList->CountAllAtoms(), "config::SaveTREMOLO - *LocalNotoGlobalNoMap[]");
     1747      LocalNotoGlobalNoMap[MolCounter] = new int[MolList->CountAllAtoms()];
     1748      for (int i=0;i<MolList->CountAllAtoms();i++)
     1749        LocalNotoGlobalNoMap[MolCounter][i] = NULL;
    17421750
    17431751      (*MolWalker)->SetIndexedArrayForEachAtomTo( LocalNotoGlobalNoMap[MolCounter], &atom::nr, IncrementalAbsoluteValue, &AtomNo);
     
    17791787  delete(fname);
    17801788  for(size_t i=0;i<MolList->ListOfMolecules.size(); i++)
    1781     Free(&LocalNotoGlobalNoMap[i]);
    1782   Free(&LocalNotoGlobalNoMap);
     1789    delete[](LocalNotoGlobalNoMap[i]);
     1790  delete[](LocalNotoGlobalNoMap);
    17831791
    17841792  return true;
     
    19381946  char *dummy1 = NULL;
    19391947  char *dummy = NULL;
    1940   char * const free_dummy = Malloc<char>(256, "config::ParseForParameter: *free_dummy");    // pointers in the line that is read in per step
     1948  char free_dummy[MAXSTRINGSIZE];    // pointers in the line that is read in per step
    19411949  dummy1 = free_dummy;
    19421950
     
    19541962      if (file->eof()) {
    19551963        if ((critical) && (found == 0)) {
    1956           Free(free_dummy);
    19571964          //Error(InitReading, name);
    19581965          fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
     
    19621969          file->clear();
    19631970          file->seekg(file_position, ios::beg);  // rewind to start position
    1964           Free(free_dummy);
    19651971          return 0;
    19661972        }
     
    19931999        dummy = strchr(dummy1, '\n'); // set on line end then (whole line = keyword)
    19942000        //fprintf(stderr,"Error: Cannot find tabs or spaces on line %i in search for %s\n", line, name);
    1995         //Free((void **)&free_dummy);
    19962001        //Error(FileOpenParams, NULL);
    19972002      } else {
     
    20142019              if (file->eof()) {
    20152020                if ((critical) && (found == 0)) {
    2016                   Free(free_dummy);
    20172021                  //Error(InitReading, name);
    20182022                  fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
     
    20222026                  file->clear();
    20232027                  file->seekg(file_position, ios::beg);  // rewind to start position
    2024                   Free(free_dummy);
    20252028                  return 0;
    20262029                }
     
    20632066                  if (critical) {
    20642067                    if (verbose) fprintf(stderr,"Error: EoL at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name);
    2065                     Free(free_dummy);
    20662068                    //return 0;
    20672069                    exit(255);
     
    20712073                    file->clear();
    20722074                    file->seekg(file_position, ios::beg);  // rewind to start position
    2073                     Free(free_dummy);
    20742075                    return 0;
    20752076                  }
     
    20842085                  file->seekg(file_position, ios::beg);  // rewind to start position
    20852086                }
    2086                 Free(free_dummy);
    20872087                return 0;
    20882088              }
     
    21402140  if ((type >= row_int) && (verbose))
    21412141    fprintf(stderr,"\n");
    2142   Free(free_dummy);
    21432142  if (!sequential) {
    21442143    file->clear();
     
    22212220        dummy = strchr(dummy1, '\n'); // set on line end then (whole line = keyword)
    22222221        //fprintf(stderr,"Error: Cannot find tabs or spaces on line %i in search for %s\n", line, name);
    2223         //Free(&free_dummy);
    22242222        //Error(FileOpenParams, NULL);
    22252223      } else {
Note: See TracChangeset for help on using the changeset viewer.