Changeset 920c70 for src/parser.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/parser.cpp

    r87b597 r920c70  
    5959MatrixContainer::MatrixContainer() {
    6060  Indices = NULL;
    61   Header = Malloc<char*>(1, "MatrixContainer::MatrixContainer: **Header");
    62   Matrix = Malloc<double**>(1, "MatrixContainer::MatrixContainer: ***Matrix"); // one more each for the total molecule
    63   RowCounter = Malloc<int>(1, "MatrixContainer::MatrixContainer: *RowCounter");
    64   ColumnCounter = Malloc<int>(1, "MatrixContainer::MatrixContainer: *ColumnCounter");
     61  Header = new char*[1];
     62  Matrix = new double**[1]; // one more each for the total molecule
     63  RowCounter = new int[1];
     64  ColumnCounter = new int[1];
    6565  Header[0] = NULL;
    6666  Matrix[0] = NULL;
     
    7777      if ((ColumnCounter != NULL) && (RowCounter != NULL)) {
    7878          for(int j=RowCounter[i]+1;j--;)
    79             Free(&Matrix[i][j]);
    80         Free(&Matrix[i]);
     79            delete[](Matrix[i][j]);
     80          delete[](Matrix[i]);
    8181      }
    8282    }
    8383    if ((ColumnCounter != NULL) && (RowCounter != NULL) && (Matrix[MatrixCounter] != NULL))
    8484      for(int j=RowCounter[MatrixCounter]+1;j--;)
    85         Free(&Matrix[MatrixCounter][j]);
     85        delete[](Matrix[MatrixCounter][j]);
    8686    if (MatrixCounter != 0)
    87       Free(&Matrix[MatrixCounter]);
    88     Free(&Matrix);
     87      delete[](Matrix[MatrixCounter]);
     88    delete[](Matrix);
    8989  }
    9090  if (Indices != NULL)
    9191    for(int i=MatrixCounter+1;i--;) {
    92       Free(&Indices[i]);
    93     }
    94   Free(&Indices);
     92      delete[](Indices[i]);
     93    }
     94  delete[](Indices);
    9595 
    9696  if (Header != NULL)
    9797    for(int i=MatrixCounter+1;i--;)
    98       Free(&Header[i]);
    99   Free(&Header);
    100   Free(&RowCounter);
    101   Free(&ColumnCounter);
     98      delete[](Header[i]);
     99  delete[](Header);
     100  delete[](RowCounter);
     101  delete[](ColumnCounter);
    102102};
    103103
     
    112112  if (Matrix == NULL) {
    113113    DoLog(0) && (Log() << Verbose(0) << " with trivial mapping." << endl);
    114     Indices = Malloc<int*>(MatrixCounter + 1, "MatrixContainer::InitialiseIndices: **Indices");
     114    Indices = new int*[MatrixCounter + 1];
    115115    for(int i=MatrixCounter+1;i--;) {
    116       Indices[i] = Malloc<int>(RowCounter[i], "MatrixContainer::InitialiseIndices: *Indices[]");
     116      Indices[i] = new int[RowCounter[i]];
    117117      for(int j=RowCounter[i];j--;)
    118118        Indices[i][j] = j;
     
    122122    if (MatrixCounter != Matrix->MatrixCounter)
    123123      return false;
    124     Indices = Malloc<int*>(MatrixCounter + 1, "MatrixContainer::InitialiseIndices: **Indices");
     124    Indices = new int*[MatrixCounter + 1];
    125125    for(int i=MatrixCounter+1;i--;) {
    126126      if (RowCounter[i] != Matrix->RowCounter[i])
    127127        return false;
    128       Indices[i] = Malloc<int>(Matrix->RowCounter[i], "MatrixContainer::InitialiseIndices: *Indices[]");
     128      Indices[i] = new int[Matrix->RowCounter[i]];
    129129      for(int j=Matrix->RowCounter[i];j--;) {
    130130        Indices[i][j] = Matrix->Indices[i][j];
     
    166166
    167167  // parse header
    168   Header[MatrixNr] = Malloc<char>(1024, "MatrixContainer::ParseMatrix: *Header[]");
     168  Header[MatrixNr] = new char[1024];
    169169  for (int m=skiplines+1;m--;)
    170170    input.getline(Header[MatrixNr], 1023);
     
    205205  // allocate matrix if it's not zero dimension in one direction
    206206  if ((ColumnCounter[MatrixNr] > 0) && (RowCounter[MatrixNr] > -1)) {
    207     Matrix[MatrixNr] = Malloc<double*>(RowCounter[MatrixNr] + 1, "MatrixContainer::ParseMatrix: **Matrix[]");
     207    Matrix[MatrixNr] = new double*[RowCounter[MatrixNr] + 1];
    208208 
    209209    // parse in each entry for this matrix
     
    217217    strncpy(Header[MatrixNr], line.str().c_str(), 1023); 
    218218    for(int j=0;j<RowCounter[MatrixNr];j++) {
    219       Matrix[MatrixNr][j] = Malloc<double>(ColumnCounter[MatrixNr], "MatrixContainer::ParseMatrix: *Matrix[][]");
     219      Matrix[MatrixNr][j] = new double[ColumnCounter[MatrixNr]];
    220220      input.getline(filename, 1023);
    221221      stringstream lines(filename);
     
    227227        //Log() << Verbose(1) << " " << setprecision(2) << Matrix[MatrixNr][j][k] << endl;
    228228      }
    229       Matrix[MatrixNr][ RowCounter[MatrixNr] ] = Malloc<double>(ColumnCounter[MatrixNr], "MatrixContainer::ParseMatrix: *Matrix[RowCounter[MatrixNr]][]");
     229      Matrix[MatrixNr][ RowCounter[MatrixNr] ] = new double[ColumnCounter[MatrixNr]];
    230230      for(int j=ColumnCounter[MatrixNr];j--;)
    231231        Matrix[MatrixNr][ RowCounter[MatrixNr] ][j] = 0.;
     
    281281
    282282  DoLog(0) && (Log() << Verbose(0) << "Parsing through each fragment and retrieving " << prefix << suffix << "." << endl);
    283   Header = ReAlloc<char*>(Header, MatrixCounter + 1, "MatrixContainer::ParseFragmentMatrix: **Header"); // one more each for the total molecule
    284   Matrix = ReAlloc<double**>(Matrix, MatrixCounter + 1, "MatrixContainer::ParseFragmentMatrix: ***Matrix"); // one more each for the total molecule
    285   RowCounter = ReAlloc<int>(RowCounter, MatrixCounter + 1, "MatrixContainer::ParseFragmentMatrix: *RowCounter");
    286   ColumnCounter = ReAlloc<int>(ColumnCounter, MatrixCounter + 1, "MatrixContainer::ParseFragmentMatrix: *ColumnCounter");
     283  delete[](Header);
     284  delete[](Matrix);
     285  delete[](RowCounter);
     286  delete[](ColumnCounter);
     287  Header = new char*[MatrixCounter + 1]; // one more each for the total molecule
     288  Matrix = new double**[MatrixCounter + 1]; // one more each for the total molecule
     289  RowCounter = new int[MatrixCounter + 1];
     290  ColumnCounter = new int[MatrixCounter + 1];
    287291  for(int i=MatrixCounter+1;i--;) {
    288292    Matrix[i] = NULL;
     
    298302    if (!ParseMatrix(file.str().c_str(), skiplines, skipcolumns, i))
    299303      return false;
    300     Free(&FragmentNumber);
     304    delete[](FragmentNumber);
    301305  }
    302306  return true;
     
    313317{
    314318  MatrixCounter = MCounter;
    315   Header = Malloc<char*>(MatrixCounter + 1, "MatrixContainer::AllocateMatrix: *Header");
    316   Matrix = Malloc<double**>(MatrixCounter + 1, "MatrixContainer::AllocateMatrix: ***Matrix"); // one more each for the total molecule
    317   RowCounter = Malloc<int>(MatrixCounter + 1, "MatrixContainer::AllocateMatrix: *RowCounter");
    318   ColumnCounter = Malloc<int>(MatrixCounter + 1, "MatrixContainer::AllocateMatrix: *ColumnCounter");
     319  Header = new char*[MatrixCounter + 1];
     320  Matrix = new double**[MatrixCounter + 1]; // one more each for the total molecule
     321  RowCounter = new int[MatrixCounter + 1];
     322  ColumnCounter = new int[MatrixCounter + 1];
    319323  for(int i=MatrixCounter+1;i--;) {
    320     Header[i] = Malloc<char>(1024, "MatrixContainer::AllocateMatrix: *Header[i]");
     324    Header[i] = new char[1024];
    321325    strncpy(Header[i], GivenHeader[i], 1023);
    322326    RowCounter[i] = RCounter[i];
    323327    ColumnCounter[i] = CCounter[i];
    324     Matrix[i] = Malloc<double*>(RowCounter[i] + 1, "MatrixContainer::AllocateMatrix: **Matrix[]");
     328    Matrix[i] = new double*[RowCounter[i] + 1];
    325329    for(int j=RowCounter[i]+1;j--;) {
    326       Matrix[i][j] = Malloc<double>(ColumnCounter[i], "MatrixContainer::AllocateMatrix: *Matrix[][]");
     330      Matrix[i][j] = new double[ColumnCounter[i]];
    327331      for(int k=ColumnCounter[i];k--;)
    328332        Matrix[i][j][k] = 0.;
     
    474478    FragmentNumber = FixedDigitNumber(MatrixCounter, i);
    475479    line << name << FRAGMENTPREFIX << FragmentNumber << "/" << prefix;
    476     Free(&FragmentNumber);
     480    delete[](FragmentNumber);
    477481    output.open(line.str().c_str(), ios::out);
    478482    if (output == NULL) {
     
    530534{
    531535  DoLog(0) && (Log() << Verbose(0) << "Parsing energy indices." << endl);
    532   Indices = Malloc<int*>(MatrixCounter + 1, "EnergyMatrix::ParseIndices: **Indices");
     536  Indices = new int*[MatrixCounter + 1];
    533537  for(int i=MatrixCounter+1;i--;) {
    534     Indices[i] = Malloc<int>(RowCounter[i], "EnergyMatrix::ParseIndices: *Indices[]");
     538    Indices[i] = new int[RowCounter[i]];
    535539    for(int j=RowCounter[i];j--;)
    536540      Indices[i][j] = j;
     
    589593    // allocate last plus one matrix
    590594    DoLog(0) && (Log() << Verbose(0) << "Allocating last plus one matrix with " << (RowCounter[MatrixCounter]+1) << " rows and " << ColumnCounter[MatrixCounter] << " columns." << endl);
    591     Matrix[MatrixCounter] = Malloc<double*>(RowCounter[MatrixCounter] + 1, "MatrixContainer::ParseFragmentMatrix: **Matrix[]");
     595    Matrix[MatrixCounter] = new double*[RowCounter[MatrixCounter] + 1];
    592596    for(int j=0;j<=RowCounter[MatrixCounter];j++)
    593       Matrix[MatrixCounter][j] = Malloc<double>(ColumnCounter[MatrixCounter], "MatrixContainer::ParseFragmentMatrix: *Matrix[][]");
     597      Matrix[MatrixCounter][j] = new double[ColumnCounter[MatrixCounter]];
    594598   
    595599    // try independently to parse global energysuffix file if present
     
    616620
    617621  DoLog(0) && (Log() << Verbose(0) << "Parsing force indices for " << MatrixCounter << " matrices." << endl);
    618   Indices = Malloc<int*>(MatrixCounter + 1, "ForceMatrix::ParseIndices: **Indices");
     622  Indices = new int*[MatrixCounter + 1];
    619623  line << name << FRAGMENTPREFIX << FORCESFILE;
    620624  input.open(line.str().c_str(), ios::in);
     
    629633    line.str(filename);
    630634    // parse the values
    631     Indices[i] = Malloc<int>(RowCounter[i], "ForceMatrix::ParseIndices: *Indices[]");
     635    Indices[i] = new int[RowCounter[i]];
    632636    FragmentNumber = FixedDigitNumber(MatrixCounter, i);
    633637    //Log() << Verbose(0) << FRAGMENTPREFIX << FragmentNumber << "[" << RowCounter[i] << "]:";
    634     Free(&FragmentNumber);
     638    delete[](FragmentNumber);
    635639    for(int j=0;(j<RowCounter[i]) && (!line.eof());j++) {
    636640      line >> Indices[i][j];
     
    639643    //Log() << Verbose(0) << endl;
    640644  }
    641   Indices[MatrixCounter] = Malloc<int>(RowCounter[MatrixCounter], "ForceMatrix::ParseIndices: *Indices[]");
     645  Indices[MatrixCounter] = new int[RowCounter[MatrixCounter]];
    642646  for(int j=RowCounter[MatrixCounter];j--;) {
    643647    Indices[MatrixCounter][j] = j;
     
    725729    // allocate last plus one matrix
    726730    DoLog(0) && (Log() << Verbose(0) << "Allocating last plus one matrix with " << (RowCounter[MatrixCounter]+1) << " rows and " << ColumnCounter[MatrixCounter] << " columns." << endl);
    727     Matrix[MatrixCounter] = Malloc<double*>(RowCounter[MatrixCounter] + 1, "MatrixContainer::ParseFragmentMatrix: **Matrix[]");
     731    Matrix[MatrixCounter] = new double*[RowCounter[MatrixCounter] + 1];
    728732    for(int j=0;j<=RowCounter[MatrixCounter];j++)
    729       Matrix[MatrixCounter][j] = Malloc<double>(ColumnCounter[MatrixCounter], "MatrixContainer::ParseFragmentMatrix: *Matrix[][]");
     733      Matrix[MatrixCounter][j] = new double[ColumnCounter[MatrixCounter]];
    730734
    731735    // try independently to parse global forcesuffix file if present
     
    754758 
    755759  DoLog(0) && (Log() << Verbose(0) << "Parsing hessian indices for " << MatrixCounter << " matrices." << endl);
    756   Indices = Malloc<int*>(MatrixCounter + 1, "HessianMatrix::ParseIndices: **Indices");
     760  Indices = new int*[MatrixCounter + 1];
    757761  line << name << FRAGMENTPREFIX << FORCESFILE;
    758762  input.open(line.str().c_str(), ios::in);
     
    767771    line.str(filename);
    768772    // parse the values
    769     Indices[i] = Malloc<int>(RowCounter[i], "HessianMatrix::ParseIndices: *Indices[]");
     773    Indices[i] = new int[RowCounter[i]];
    770774    FragmentNumber = FixedDigitNumber(MatrixCounter, i);
    771775    //Log() << Verbose(0) << FRAGMENTPREFIX << FragmentNumber << "[" << RowCounter[i] << "]:";
    772     Free(&FragmentNumber);
     776    delete[](FragmentNumber);
    773777    for(int j=0;(j<RowCounter[i]) && (!line.eof());j++) {
    774778      line >> Indices[i][j];
     
    777781    //Log() << Verbose(0) << endl;
    778782  }
    779   Indices[MatrixCounter] = Malloc<int>(RowCounter[MatrixCounter], "HessianMatrix::ParseIndices: *Indices[]");
     783  Indices[MatrixCounter] = new int[RowCounter[MatrixCounter]];
    780784  for(int j=RowCounter[MatrixCounter];j--;) {
    781785    Indices[MatrixCounter][j] = j;
     
    953957    // allocate last plus one matrix
    954958    DoLog(0) && (Log() << Verbose(0) << "Allocating last plus one matrix with " << (RowCounter[MatrixCounter]+1) << " rows and " << ColumnCounter[MatrixCounter] << " columns." << endl);
    955     Matrix[MatrixCounter] = Malloc<double*>(RowCounter[MatrixCounter] + 1, "MatrixContainer::ParseFragmentMatrix: **Matrix[]");
     959    Matrix[MatrixCounter] = new double*[RowCounter[MatrixCounter] + 1];
    956960    for(int j=0;j<=RowCounter[MatrixCounter];j++)
    957       Matrix[MatrixCounter][j] = Malloc<double>(ColumnCounter[MatrixCounter], "MatrixContainer::ParseFragmentMatrix: *Matrix[][]");
     961      Matrix[MatrixCounter][j] = new double[ColumnCounter[MatrixCounter]];
    958962
    959963    // try independently to parse global forcesuffix file if present
     
    985989KeySetsContainer::~KeySetsContainer() {
    986990  for(int i=FragmentCounter;i--;)
    987     Free(&KeySets[i]);
     991    delete[](KeySets[i]);
    988992  for(int i=Order;i--;)
    989     Free(&OrderSet[i]);
    990   Free(&KeySets);
    991   Free(&OrderSet);
    992   Free(&AtomCounter);
    993   Free(&FragmentsPerOrder);
     993    delete[](OrderSet[i]);
     994  delete[](KeySets);
     995  delete[](OrderSet);
     996  delete[](AtomCounter);
     997  delete[](FragmentsPerOrder);
    994998};
    995999
     
    10081012  FragmentCounter = FCounter;
    10091013  DoLog(0) && (Log() << Verbose(0) << "Parsing key sets." << endl);
    1010   KeySets = Malloc<int*>(FragmentCounter, "KeySetsContainer::ParseKeySets: **KeySets");
     1014  KeySets = new int*[FragmentCounter];
    10111015  for(int i=FragmentCounter;i--;)
    10121016    KeySets[i] = NULL;
     
    10181022  }
    10191023
    1020   AtomCounter = Malloc<int>(FragmentCounter, "KeySetsContainer::ParseKeySets: *RowCounter");
     1024  AtomCounter = new int[FragmentCounter];
    10211025  for(int i=0;(i<FragmentCounter) && (!input.eof());i++) {
    10221026    stringstream line;
    10231027    AtomCounter[i] = ACounter[i];
    10241028    // parse the values
    1025     KeySets[i] = Malloc<int>(AtomCounter[i], "KeySetsContainer::ParseKeySets: *KeySets[]");
     1029    KeySets[i] = new int[AtomCounter[i]];
    10261030    for(int j=AtomCounter[i];j--;)
    10271031      KeySets[i][j] = -1;
    10281032    FragmentNumber = FixedDigitNumber(FragmentCounter, i);
    10291033    //Log() << Verbose(0) << FRAGMENTPREFIX << FragmentNumber << "[" << AtomCounter[i] << "]:";
    1030     Free(&FragmentNumber);
     1034    delete[](FragmentNumber);
    10311035    input.getline(filename, 1023);
    10321036    line.str(filename);
     
    10621066
    10631067  // scan through all to determine fragments per order
    1064   FragmentsPerOrder = Malloc<int>(Order, "KeySetsContainer::ParseManyBodyTerms: *FragmentsPerOrder");
     1068  FragmentsPerOrder = new int[Order];
    10651069  for(int i=Order;i--;)
    10661070    FragmentsPerOrder[i] = 0;
     
    10761080
    10771081  // scan through all to gather indices to each order set
    1078   OrderSet = Malloc<int*>(Order, "KeySetsContainer::ParseManyBodyTerms: **OrderSet");
     1082  OrderSet = new int*[Order];
    10791083  for(int i=Order;i--;)
    1080     OrderSet[i] = Malloc<int>(FragmentsPerOrder[i], "KeySetsContainer::ParseManyBodyTermsKeySetsContainer::ParseManyBodyTerms: *OrderSet[]");
     1084    OrderSet[i] = new int[FragmentsPerOrder[i]];
    10811085  for(int i=Order;i--;)
    10821086    FragmentsPerOrder[i] = 0;
Note: See TracChangeset for help on using the changeset viewer.