Changeset 29812d


Ignore:
Timestamp:
Sep 21, 2009, 11:48:42 AM (16 years ago)
Author:
Saskia Metzler <metzler@…>
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:
b66c22, c30180
Parents:
89c8b2
Message:

Ticket 11: use templates and/or traits to fix Malloc/ReAlloc-Free warnings in a clean manner

Location:
src
Files:
3 added
15 edited

Legend:

Unmodified
Added
Removed
  • src/Makefile.am

    r89c8b2 r29812d  
    22HEADER = atom.hpp bond.hpp boundary.hpp config.hpp defs.hpp element.hpp ellipsoid.hpp helpers.hpp leastsquaremin.hpp linkedcell.hpp molecules.hpp parser.hpp periodentafel.hpp stackclass.hpp tesselation.hpp tesselationhelpers.hpp vector.hpp verbose.hpp
    33
    4 noinst_PROGRAMS =  VectorUnitTest
     4noinst_PROGRAMS =  VectorUnitTest MemoryAllocatorUnitTest
    55
    66bin_PROGRAMS = molecuilder joiner analyzer
     
    1111analyzer_SOURCES = analyzer.cpp datacreator.cpp element.cpp helpers.cpp periodentafel.cpp parser.cpp verbose.cpp helpers.hpp periodentafel.hpp parser.hpp datacreator.hpp
    1212
    13 TESTS = VectorUnitTest
     13TESTS = VectorUnitTest MemoryAllocatorUnitTest
    1414check_PROGRAMS = $(TESTS)
    1515VectorUnitTest_SOURCES = defs.hpp helpers.cpp helpers.hpp leastsquaremin.cpp leastsquaremin.hpp vectorunittest.cpp vectorunittest.hpp vector.cpp vector.hpp verbose.cpp verbose.hpp
     
    1717VectorUnitTest_LDFLAGS = $(CPPUNIT_LIBS) -ldl
    1818
     19MemoryAllocatorUnitTest_SOURCES = defs.hpp helpers.cpp helpers.hpp memoryallocatorunittest.cpp memoryallocatorunittest.hpp memoryallocator.hpp verbose.cpp verbose.hpp
     20MemoryAllocatorUnitTest_CXXFLAGS = $(CPPUNIT_CFLAGS)
     21MemoryAllocatorUnitTest_LDFLAGS = $(CPPUNIT_LIBS) -ldl
     22
     23
    1924EXTRA_DIST = ${molecuilder_DATA}
  • src/analyzer.cpp

    r89c8b2 r29812d  
    1010#include "datacreator.hpp"
    1111#include "helpers.hpp"
     12#include "memoryallocator.hpp"
    1213#include "parser.hpp"
    1314#include "periodentafel.hpp"
     
    7273    return 1;
    7374  } else {
    74     dir = (char *) Malloc(sizeof(char)*(strlen(argv[2])+2), "main: *dir");
     75    dir = Malloc<char>(strlen(argv[2]) + 2, "main: *dir");
    7576    strcpy(dir, "/");
    7677    strcat(dir, argv[2]);
     
    555556  // ++++++++++++++++ exit ++++++++++++++++++++++++++++++++++
    556557  delete(periode);
    557   Free((void **)&dir, "main: *dir");
     558  Free(&dir);
    558559  cout << "done." << endl;
    559560  return 0;
  • src/atom.cpp

    r89c8b2 r29812d  
    66
    77#include "atom.hpp"
     8#include "memoryallocator.hpp"
    89
    910/************************************* Functions for class atom *************************************/
     
    6162atom::~atom()
    6263{
    63   Free((void **)&ComponentNr, "atom::~atom: *ComponentNr");
     64  Free(&ComponentNr);
    6465};
    6566
  • src/boundary.cpp

    r89c8b2 r29812d  
    66
    77#include "boundary.hpp"
     8#include "memoryallocator.hpp"
    89
    910#include<gsl/gsl_poly.h>
  • src/config.cpp

    r89c8b2 r29812d  
    66
    77#include "config.hpp"
     8#include "memoryallocator.hpp"
    89
    910/******************************** Functions for class ConfigFileBuffer **********************/
     
    8687    return;
    8788  } else
    88     buffer = (char **) Malloc(sizeof(char *)*NoLines, "ConfigFileBuffer::ConfigFileBuffer: **buffer");
     89    buffer = Malloc<char*>(NoLines, "ConfigFileBuffer::ConfigFileBuffer: **buffer");
    8990
    9091  // scan each line and put into buffer
     
    9293  int i;
    9394  do {
    94     buffer[lines] = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "ConfigFileBuffer::ConfigFileBuffer: *buffer[]");
     95    buffer[lines] = Malloc<char>(MAXSTRINGSIZE, "ConfigFileBuffer::ConfigFileBuffer: *buffer[]");
    9596    file->getline(buffer[lines], MAXSTRINGSIZE-1);
    9697    i = strlen(buffer[lines]);
     
    112113{
    113114  for(int i=0;i<NoLines;++i)
    114     Free((void **)&buffer[i], "ConfigFileBuffer::~ConfigFileBuffer: *buffer[]");
    115   Free((void **)&buffer, "ConfigFileBuffer::~ConfigFileBuffer: **buffer");
    116   Free((void **)&LineMapping, "ConfigFileBuffer::~ConfigFileBuffer: *LineMapping");
     115    Free(&buffer[i]);
     116  Free(&buffer);
     117  Free(&LineMapping);
    117118}
    118119
     
    122123void ConfigFileBuffer::InitMapping()
    123124{
    124   LineMapping = (int *) Malloc(sizeof(int)*NoLines, "ConfigFileBuffer::InitMapping: *LineMapping");
     125  LineMapping = Malloc<int>(NoLines, "ConfigFileBuffer::InitMapping: *LineMapping");
    125126  for (int i=0;i<NoLines;i++)
    126127    LineMapping[i] = i;
     
    163164config::config()
    164165{
    165   mainname = (char *) MallocString(sizeof(char)*MAXSTRINGSIZE,"config constructor: mainname");
    166   defaultpath = (char *) MallocString(sizeof(char)*MAXSTRINGSIZE,"config constructor: defaultpath");
    167   pseudopotpath = (char *) MallocString(sizeof(char)*MAXSTRINGSIZE,"config constructor: pseudopotpath");
    168   databasepath = (char *) MallocString(sizeof(char)*MAXSTRINGSIZE,"config constructor: databasepath");
    169   configpath = (char *) MallocString(sizeof(char)*MAXSTRINGSIZE,"config constructor: configpath");
    170   configname = (char *) MallocString(sizeof(char)*MAXSTRINGSIZE,"config constructor: configname");
    171   ThermostatImplemented = (int *) Malloc((MaxThermostats)*(sizeof(int)), "config constructor: *ThermostatImplemented");
    172   ThermostatNames = (char **) Malloc((MaxThermostats)*(sizeof(char *)), "config constructor: *ThermostatNames");
     166  mainname = Malloc<char>(MAXSTRINGSIZE,"config constructor: mainname");
     167  defaultpath = Malloc<char>(MAXSTRINGSIZE,"config constructor: defaultpath");
     168  pseudopotpath = Malloc<char>(MAXSTRINGSIZE,"config constructor: pseudopotpath");
     169  databasepath = Malloc<char>(MAXSTRINGSIZE,"config constructor: databasepath");
     170  configpath = Malloc<char>(MAXSTRINGSIZE,"config constructor: configpath");
     171  configname = Malloc<char>(MAXSTRINGSIZE,"config constructor: configname");
     172  ThermostatImplemented = Malloc<int>(MaxThermostats, "config constructor: *ThermostatImplemented");
     173  ThermostatNames = Malloc<char*>(MaxThermostats, "config constructor: *ThermostatNames");
    173174  for (int j=0;j<MaxThermostats;j++)
    174     ThermostatNames[j] = (char *) MallocString(12*(sizeof(char)), "config constructor: ThermostatNames[]");
     175    ThermostatNames[j] = Malloc<char>(12, "config constructor: ThermostatNames[]");
    175176  Thermostat = 4;
    176177  alpha = 0.;
     
    263264config::~config()
    264265{
    265   Free((void **)&mainname, "config::~config: *mainname");
    266   Free((void **)&defaultpath, "config::~config: *defaultpath");
    267   Free((void **)&pseudopotpath, "config::~config: *pseudopotpath");
    268   Free((void **)&databasepath, "config::~config: *databasepath");
    269   Free((void **)&configpath, "config::~config: *configpath");
    270   Free((void **)&configname, "config::~config: *configname");
    271   Free((void **)&ThermostatImplemented, "config::~config: *ThermostatImplemented");
     266  Free(&mainname);
     267  Free(&defaultpath);
     268  Free(&pseudopotpath);
     269  Free(&databasepath);
     270  Free(&configpath);
     271  Free(&configname);
     272  Free(&ThermostatImplemented);
    272273  for (int j=0;j<MaxThermostats;j++)
    273     Free((void **)&ThermostatNames[j], "config::~config: *ThermostatNames[]");
    274   Free((void **)&ThermostatNames, "config::~config: **ThermostatNames");
     274    Free(&ThermostatNames[j]);
     275  Free(&ThermostatNames);
    275276};
    276277
     
    280281void config::InitThermostats(class ConfigFileBuffer *fb)
    281282{
    282   char *thermo = MallocString(12, "IonsInitRead: thermo");
     283  char *thermo = Malloc<char>(12, "IonsInitRead: thermo");
    283284  int verbose = 0;
    284285
     
    347348    Thermostat = None;
    348349  }
    349   Free((void **)&thermo, "InitThermostats: thermo");
     350  Free(&thermo);
    350351};
    351352
     
    15331534  long file_position = file->tellg(); // mark current position
    15341535  char *dummy1, *dummy, *free_dummy;    // pointers in the line that is read in per step
    1535   dummy1 = free_dummy = (char *) Malloc(256 * sizeof(char), "config::ParseForParameter: *free_dummy");
     1536  dummy1 = free_dummy = Malloc<char>(256, "config::ParseForParameter: *free_dummy");
    15361537
    15371538  //fprintf(stderr,"Parsing for %s\n",name);
     
    15481549      if (file->eof()) {
    15491550        if ((critical) && (found == 0)) {
    1550           Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
     1551          Free(&free_dummy);
    15511552          //Error(InitReading, name);
    15521553          fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
     
    15561557          file->clear();
    15571558          file->seekg(file_position, ios::beg);  // rewind to start position
    1558           Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
     1559          Free(&free_dummy);
    15591560          return 0;
    15601561        }
     
    16081609              if (file->eof()) {
    16091610                if ((critical) && (found == 0)) {
    1610                   Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
     1611                  Free(&free_dummy);
    16111612                  //Error(InitReading, name);
    16121613                  fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
     
    16161617                  file->clear();
    16171618                  file->seekg(file_position, ios::beg);  // rewind to start position
    1618                   Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
     1619                  Free(&free_dummy);
    16191620                  return 0;
    16201621                }
     
    16571658                  if (critical) {
    16581659                    if (verbose) fprintf(stderr,"Error: EoL at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name);
    1659                     Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
     1660                    Free(&free_dummy);
    16601661                    //return 0;
    16611662                    exit(255);
     
    16651666                    file->clear();
    16661667                    file->seekg(file_position, ios::beg);  // rewind to start position
    1667                     Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
     1668                    Free(&free_dummy);
    16681669                    return 0;
    16691670                  }
     
    16781679                  file->seekg(file_position, ios::beg);  // rewind to start position
    16791680                }
    1680                 Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
     1681                Free(&free_dummy);
    16811682                return 0;
    16821683              }
     
    17321733    }
    17331734  }
    1734   if ((type >= row_int) && (verbose)) fprintf(stderr,"\n");
    1735   Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
     1735  if ((type >= row_int) && (verbose))
     1736    fprintf(stderr,"\n");
     1737  Free(&free_dummy);
    17361738  if (!sequential) {
    17371739    file->clear();
     
    18111813        dummy = strchr(dummy1, '\n'); // set on line end then (whole line = keyword)
    18121814        //fprintf(stderr,"Error: Cannot find tabs or spaces on line %i in search for %s\n", line, name);
    1813         //Free((void **)&free_dummy);
     1815        //Free(&free_dummy);
    18141816        //Error(FileOpenParams, NULL);
    18151817      } else {
  • src/defs.hpp

    r89c8b2 r29812d  
    77#ifndef DEFS_HPP_
    88#define DEFS_HPP_
    9 
    10 using namespace std;
    119
    1210#define MYEPSILON 1e-13   //!< machine epsilon precision
  • src/helpers.cpp

    r89c8b2 r29812d  
    3434void debug_in(const char *output, const char *file, const int line) {}  // print nothing
    3535#endif
    36 
    37 /** Wrapper for allocating'ing a memory range with *output if it fails.
    38  * \param size number of chars to alloc for \a *buffer
    39  * \param *output message if malloc fails
    40  * \return pointer to memory range
    41  */
    42 void * Malloc(size_t size, const char* output)
    43 {
    44   void *buffer = NULL;
    45   buffer = (void *)malloc(size); // alloc
    46   if (buffer == NULL)
    47     cout << Verbose(0) << "Malloc failed - pointer is NULL: " << output << endl;
    48   return(buffer);
    49 };
    50 
    51 /** Wrapper for allocating'ing a memory range with *output if it fails.
    52  * \param size number of chars to alloc for \a *buffer
    53  * \param *output message if malloc fails
    54  * \return pointer to memory range
    55  */
    56 void * Calloc(size_t size, const char* output)
    57 {
    58   void *buffer = NULL;
    59   buffer = (void *)calloc(size, (size_t)0); // alloc
    60   if (buffer == NULL)
    61     cout << Verbose(0) << "Calloc failed - pointer is NULL: " << output << endl;
    62   return(buffer);
    63 };
    64 
    65 /** Wrapper for reallocating'ing a memory range with *output if it fails.
    66  * \param *OldPointer pointer to old memory range
    67  * \param size number of chars to alloc for \a *buffer
    68  * \param *output message if malloc fails
    69  * \return pointer to memory range
    70  */
    71 void * ReAlloc(void * OldPointer, size_t size, const char* output)
    72 {
    73   void *buffer = NULL;
    74   if (OldPointer == NULL)
    75     //cout << Verbose(0) << "ReAlloc impossible - old is NULL: " << output << endl;
    76     buffer = (void *)malloc(size); // malloc
    77   else
    78     buffer = (void *)realloc(OldPointer, size); // realloc
    79   if (buffer == NULL)
    80     cout << Verbose(0) << "ReAlloc failed - new is NULL: " << output << endl;
    81   return(buffer);
    82 };
    83 
    84 /** Wrapper for free'ing an allocated memory range with *output if it fails.
    85  * \param *buffer pointer to buffer to be free'd
    86  * \param *output message if free fails
    87  */
    88 void Free(void ** buffer, const char* output)
    89 {
    90   if (*buffer == NULL) {
    91     //cout << Verbose(5) << "Free not necesary: " << output << endl;
    92   } else {
    93     free(*buffer);
    94     *buffer = NULL;
    95   }
    96 };
    97 
    98 /** Malloc string array and set its length to the allocated length.
    99  * \param *output message if malloc fails
    100  * \param size number of chars to alloc for \a *buffer
    101  * \return pointer to string array
    102  */
    103 char* MallocString(size_t size, const char* output)
    104 {
    105   size_t i;
    106   char *buffer;
    107   buffer = (char *)malloc(sizeof(char) * (size+1)); // alloc
    108   if (buffer == NULL)
    109     cout << Verbose(0) << output << endl;
    110   for (i=size;i--;)  // reset
    111     buffer[i] = i % 2 == 0 ? 'p': 'c';
    112   buffer[size] = '\0'; // and set length marker on its end
    113   return(buffer);
    114 }
    11536
    11637/** modulo operator for doubles.
     
    17091  }
    17192  // allocate string
    172   returnstring = (char *) Malloc(sizeof(char)*(order+2), "FixedDigitNumber: *returnstring");
     93  returnstring = Malloc<char>(order + 2, "FixedDigitNumber: *returnstring");
    17394  // terminate  and fill string array from end backward
    17495  returnstring[order] = '\0';
     
    196117};
    197118
     119/**
     120 * Allocates a memory range using malloc().
     121 * Prints the provided error message in case of a failure.
     122 *
     123 * \param number of memory slices of type X to allocate
     124 * \param failure message which is printed if the allocation fails
     125 * \return pointer to the allocated memory range, will be NULL if a failure occurred
     126 */
     127template <> char* Malloc<char>(size_t size, const char* output)
     128{
     129  char* buffer = NULL;
     130  buffer = (char*) malloc(sizeof(char) * (size + 1));
     131  for (size_t i = size; i--;)
     132    buffer[i] = (i % 2 == 0) ? 'p': 'c';
     133  buffer[size] = '\0';
    198134
     135  if (buffer == NULL)
     136    cout << Verbose(0) << "Malloc for datatype " << typeid(char).name()
     137      << " failed - pointer is NULL: " << output << endl;
     138
     139  return buffer;
     140};
     141
     142
  • src/helpers.hpp

    r89c8b2 r29812d  
    2323#include "defs.hpp"
    2424#include "verbose.hpp"
     25#include "memoryallocator.hpp"
    2526
    2627/********************************************** helpful functions *********************************/
     
    5051void flip(double *x, double *y);
    5152int pot(int base, int n);
    52 void * Malloc(size_t size, const char* output);
    53 void * Calloc(size_t size, const char* output);
    54 void * ReAlloc(void * OldPointer, size_t size, const char* output);
    55 char* MallocString(size_t size, const char* output);
    56 void Free(void ** buffer, const char* output);
     53//void * Malloc(size_t size, const char* output);
     54//void * Calloc(size_t size, const char* output);
     55//void * ReAlloc(void * OldPointer, size_t size, const char* output);
     56//char* MallocString(size_t size, const char* output);
     57//void Free(void ** buffer, const char* output);
    5758char *FixedDigitNumber(const int FragmentNumber, const int digits);
    5859bool IsValidNumber( const char *string);
     
    9394
    9495  // allocat and fill
    95   LookupTable = (T **) Malloc(sizeof(T *)*count, "CreateFatherLookupTable - **LookupTable");
     96  LookupTable = Malloc<T*>(count, "CreateFatherLookupTable - **LookupTable");
    9697  if (LookupTable == NULL) {
    9798    cerr << "LookupTable memory allocation failed!" << endl;
     
    273274
    274275
     276
    275277#endif /*HELPERS_HPP_*/
  • src/joiner.cpp

    r89c8b2 r29812d  
    1010#include "datacreator.hpp"
    1111#include "helpers.hpp"
     12#include "memoryallocator.hpp"
    1213#include "parser.hpp"
    1314#include "periodentafel.hpp"
     
    5556    return 1;
    5657  } else {
    57     dir = (char *) Malloc(sizeof(char)*(strlen(argv[2])+2), "main: *dir");
     58    dir = Malloc<char>(strlen(argv[2]) + 2, "main: *dir");
    5859    strcpy(dir, "/");
    5960    strcat(dir, argv[2]);
     
    240241  // exit
    241242  delete(periode);
    242   Free((void **)&dir, "main: *dir");
     243  Free(&dir);
    243244  cout << "done." << endl;
    244245  return 0;
  • src/moleculelist.cpp

    r89c8b2 r29812d  
    77#include "config.hpp"
    88#include "molecules.hpp"
     9#include "memoryallocator.hpp"
    910
    1011/*********************************** Functions for class MoleculeListClass *************************/
     
    375376
    376377  // 0b. allocate memory for constants
    377   FitConstant = (double ***) Malloc(sizeof(double **) * 3, "MoleculeListClass::AddHydrogenCorrection: ***FitConstant");
     378  FitConstant = Malloc<double**>(3, "MoleculeListClass::AddHydrogenCorrection: ***FitConstant");
    378379  for (int k = 0; k < 3; k++) {
    379     FitConstant[k] = (double **) Malloc(sizeof(double *) * a, "MoleculeListClass::AddHydrogenCorrection: **FitConstant[]");
     380    FitConstant[k] = Malloc<double*>(a, "MoleculeListClass::AddHydrogenCorrection: **FitConstant[]");
    380381    for (int i = a; i--;) {
    381       FitConstant[k][i] = (double *) Malloc(sizeof(double) * b, "MoleculeListClass::AddHydrogenCorrection: *FitConstant[][]");
     382      FitConstant[k][i] = Malloc<double>(b, "MoleculeListClass::AddHydrogenCorrection: *FitConstant[][]");
    382383    }
    383384  }
     
    424425
    425426  // 0d. allocate final correction matrix
    426   correction = (double **) Malloc(sizeof(double *) * a, "MoleculeListClass::AddHydrogenCorrection: **correction");
     427  correction = Malloc<double*>(a, "MoleculeListClass::AddHydrogenCorrection: **correction");
    427428  for (int i = a; i--;)
    428     correction[i] = (double *) Malloc(sizeof(double) * b, "MoleculeListClass::AddHydrogenCorrection: *correction[]");
     429    correction[i] = Malloc<double>(b, "MoleculeListClass::AddHydrogenCorrection: *correction[]");
    429430
    430431  // 1a. go through every molecule in the list
     
    500501  output.close();
    501502  // 6. free memory of parsed matrices
    502   FitConstant = (double ***) Malloc(sizeof(double **) * a, "MoleculeListClass::AddHydrogenCorrection: ***FitConstant");
     503  FitConstant = Malloc<double**>(a, "MoleculeListClass::AddHydrogenCorrection: ***FitConstant");
    503504  for (int k = 0; k < 3; k++) {
    504     FitConstant[k] = (double **) Malloc(sizeof(double *) * a, "MoleculeListClass::AddHydrogenCorrection: **FitConstant[]");
     505    FitConstant[k] = Malloc<double*>(a, "MoleculeListClass::AddHydrogenCorrection: **FitConstant[]");
    505506    for (int i = a; i--;) {
    506       FitConstant[k][i] = (double *) Malloc(sizeof(double) * b, "MoleculeListClass::AddHydrogenCorrection: *FitConstant[][]");
     507      FitConstant[k][i] = Malloc<double>(b, "MoleculeListClass::AddHydrogenCorrection: *FitConstant[][]");
    507508    }
    508509  }
     
    665666    //outputFragment.clear();
    666667    delete (FragmentNumber);
    667     //Free((void **)&FragmentNumber, "MoleculeListClass::OutputConfigForListOfFragments: *FragmentNumber");
     668    //Free(&FragmentNumber);
    668669  }
    669670  cout << " done." << endl;
     
    808809  if ((FreeList) && (ListOfLocalAtoms != NULL)) {
    809810    // free the index lookup list
    810     Free((void **) &ListOfLocalAtoms[FragmentCounter], "MoleculeLeafClass::FillBondStructureFromReference - **ListOfLocalAtoms[]");
     811    Free(&ListOfLocalAtoms[FragmentCounter]);
    811812    if (FragmentCounter == 0) // first fragments frees the initial pointer to list
    812       Free((void **) &ListOfLocalAtoms, "MoleculeLeafClass::FillBondStructureFromReference - ***ListOfLocalAtoms");
     813      Free(&ListOfLocalAtoms);
    813814  }
    814815  FragmentCounter--;
     
    873874  if (ListOfLocalAtoms == NULL) { // allocated initial pointer
    874875    // allocate and set each field to NULL
    875     ListOfLocalAtoms = (atom ***) Malloc(sizeof(atom **) * Counter, "MoleculeLeafClass::FillBondStructureFromReference - ***ListOfLocalAtoms");
     876    ListOfLocalAtoms = Malloc<atom**>(Counter, "MoleculeLeafClass::FillBondStructureFromReference - ***ListOfLocalAtoms");
    876877    if (ListOfLocalAtoms != NULL) {
    877878      for (int i = Counter; i--;)
     
    917918  if (FragmentList == NULL) {
    918919    KeySetCounter = Count();
    919     FragmentList = (Graph **) Malloc(sizeof(Graph *) * KeySetCounter, "MoleculeLeafClass::AssignKeySetsToFragment - **FragmentList");
     920    FragmentList = Malloc<Graph*>(KeySetCounter, "MoleculeLeafClass::AssignKeySetsToFragment - **FragmentList");
    920921    for (int i = KeySetCounter; i--;)
    921922      FragmentList[i] = NULL;
     
    953954  if ((FreeList) && (ListOfLocalAtoms != NULL)) {
    954955    // free the index lookup list
    955     Free((void **) &ListOfLocalAtoms[FragmentCounter], "MoleculeLeafClass::AssignKeySetsToFragment - **ListOfLocalAtoms[]");
     956    Free(&ListOfLocalAtoms[FragmentCounter]);
    956957    if (FragmentCounter == 0) // first fragments frees the initial pointer to list
    957       Free((void **) &ListOfLocalAtoms, "MoleculeLeafClass::AssignKeySetsToFragment - ***ListOfLocalAtoms");
     958      Free(&ListOfLocalAtoms);
    958959  }
    959960  *out << Verbose(1) << "End of AssignKeySetsToFragment." << endl;
  • src/molecules.cpp

    r89c8b2 r29812d  
    66
    77#include "config.hpp"
     8#include "memoryallocator.hpp"
    89#include "molecules.hpp"
    910
     
    5556  if (ListOfBondsPerAtom != NULL)
    5657    for(int i=AtomCount;i--;)
    57       Free((void **)&ListOfBondsPerAtom[i], "molecule::~molecule: ListOfBondsPerAtom[i]");
    58   Free((void **)&ListOfBondsPerAtom, "molecule::~molecule: ListOfBondsPerAtom");
    59   Free((void **)&NumberOfBondsPerAtom, "molecule::~molecule: NumberOfBondsPerAtom");
     58      Free(&ListOfBondsPerAtom[i]);
     59  Free(&ListOfBondsPerAtom);
     60  Free(&NumberOfBondsPerAtom);
    6061  if (TesselStruct != NULL)
    6162    delete(TesselStruct);
     
    163164        NoNonHydrogen++;
    164165      if (pointer->Name == NULL) {
    165         Free((void **)&pointer->Name, "molecule::AddAtom: *pointer->Name");
    166         pointer->Name = (char *) Malloc(sizeof(char)*6, "molecule::AddAtom: *pointer->Name");
     166        Free(&pointer->Name);
     167        pointer->Name = Malloc<char>(6, "molecule::AddAtom: *pointer->Name");
    167168        sprintf(pointer->Name, "%2s%02d", pointer->type->symbol, pointer->nr+1);
    168169      }
     
    182183  if (pointer != NULL) {
    183184    atom *walker = new atom(pointer);
    184     walker->Name = (char *) Malloc(sizeof(char)*strlen(pointer->Name)+1, "atom::atom: *Name");
     185    walker->Name = Malloc<char>(strlen(pointer->Name) + 1, "atom::atom: *Name");
    185186    strcpy (walker->Name, pointer->Name);
    186187    walker->nr = last_atom++;  // increase number within molecule
     
    267268    Orthovector1.MatrixMultiplication(matrix);
    268269    InBondvector.SubtractVector(&Orthovector1); // subtract just the additional translation
    269     Free((void **)&matrix, "molecule::AddHydrogenReplacementAtom: *matrix");
     270    Free(&matrix);
    270271    bondlength = InBondvector.Norm();
    271272//    *out << Verbose(4) << "Corrected InBondvector is now: ";
     
    10801081    }
    10811082  } while (!flag);
    1082   Free((void **)&matrix, "molecule::DetermineCenter: *matrix");
     1083  Free(&matrix);
    10831084  Center.Scale(1./(double)AtomCount);
    10841085};
     
    13391340{
    13401341  stringstream zeile1, zeile2;
    1341   int *DoubleList = (int *) Malloc(Nr*sizeof(int), "PrintPermutationMap: *DoubleList");
     1342  int *DoubleList = Malloc<int>(Nr, "PrintPermutationMap: *DoubleList");
    13421343  int doubles = 0;
    13431344  for (int i=0;i<Nr;i++)
     
    13541355    doubles++;
    13551356 // *out << "Found " << doubles << " Doubles." << endl;
    1356   Free((void **)&DoubleList, "PrintPermutationMap: *DoubleList");
     1357  Free(&DoubleList);
    13571358//  *out << zeile1.str() << endl << zeile2.str() << endl;
    13581359};
     
    13881389{
    13891390  double Potential, OldPotential, OlderPotential;
    1390   PermutationMap = (atom **) Malloc(AtomCount*sizeof(atom *), "molecule::MinimiseConstrainedPotential: **PermutationMap");
    1391   DistanceMap **DistanceList = (DistanceMap **) Malloc(AtomCount*sizeof(DistanceMap *), "molecule::MinimiseConstrainedPotential: **DistanceList");
    1392   DistanceMap::iterator *DistanceIterators = (DistanceMap::iterator *) Malloc(AtomCount*sizeof(DistanceMap::iterator), "molecule::MinimiseConstrainedPotential: *DistanceIterators");
    1393   int *DoubleList = (int *) Malloc(AtomCount*sizeof(int), "molecule::MinimiseConstrainedPotential: *DoubleList");
    1394   DistanceMap::iterator *StepList = (DistanceMap::iterator *) Malloc(AtomCount*sizeof(DistanceMap::iterator), "molecule::MinimiseConstrainedPotential: *StepList");
     1391  PermutationMap = Malloc<atom*>(AtomCount, "molecule::MinimiseConstrainedPotential: **PermutationMap");
     1392  DistanceMap **DistanceList = Malloc<DistanceMap*>(AtomCount, "molecule::MinimiseConstrainedPotential: **DistanceList");
     1393  DistanceMap::iterator *DistanceIterators = Malloc<DistanceMap::iterator>(AtomCount, "molecule::MinimiseConstrainedPotential: *DistanceIterators");
     1394  int *DoubleList = Malloc<int>(AtomCount, "molecule::MinimiseConstrainedPotential: *DoubleList");
     1395  DistanceMap::iterator *StepList = Malloc<DistanceMap::iterator>(AtomCount, "molecule::MinimiseConstrainedPotential: *StepList");
    13951396  double constants[3];
    13961397  int round;
     
    14681469    }
    14691470  *out << Verbose(1) << "done." << endl;
    1470   Free((void **)&DoubleList, "molecule::MinimiseConstrainedPotential: *DoubleList");
     1471  Free(&DoubleList);
    14711472  // argument minimise the constrained potential in this injective PermutationMap
    14721473  *out << Verbose(1) << "Argument minimising the PermutationMap, at current potential " << OldPotential << " ... " << endl;
     
    15491550  for (int i=AtomCount; i--;)
    15501551    DistanceList[i]->clear();
    1551   Free((void **)&DistanceList, "molecule::MinimiseConstrainedPotential: **DistanceList");
    1552   Free((void **)&DistanceIterators, "molecule::MinimiseConstrainedPotential: *DistanceIterators");
     1552  Free(&DistanceList);
     1553  Free(&DistanceIterators);
    15531554  return ConstrainedPotential(out, PermutationMap, startstep, endstep, constants, IsAngstroem);
    15541555};
     
    16471648 
    16481649  // store the list to single step files
    1649   int *SortIndex = (int *) Malloc(AtomCount*sizeof(int), "molecule::LinearInterpolationBetweenConfiguration: *SortIndex");
     1650  int *SortIndex = Malloc<int>(AtomCount, "molecule::LinearInterpolationBetweenConfiguration: *SortIndex");
    16501651  for (int i=AtomCount; i--; )
    16511652    SortIndex[i] = i;
     
    16531654 
    16541655  // free and return
    1655   Free((void **)&PermutationMap, "molecule::MinimiseConstrainedPotential: *PermutationMap");
     1656  Free(&PermutationMap);
    16561657  delete(MoleculePerStep);
    16571658  return status;
     
    17121713      ConstrainedPotentialEnergy = MinimiseConstrainedPotential(out, PermutationMap,configuration.DoConstrainedMD, 0, configuration.GetIsAngstroem());
    17131714      EvaluateConstrainedForces(out, configuration.DoConstrainedMD, 0, PermutationMap, &Force);
    1714       Free((void **)&PermutationMap, "molecule::MinimiseConstrainedPotential: *PermutationMap");
     1715      Free(&PermutationMap);
    17151716    }
    17161717   
     
    24122413        if (Walker->type->Z != 1) // count non-hydrogen atoms whilst at it
    24132414          NoNonHydrogen++;
    2414         Free((void **)&Walker->Name, "molecule::CountAtoms: *walker->Name");
    2415         Walker->Name = (char *) Malloc(sizeof(char)*6, "molecule::CountAtoms: *walker->Name");
     2415        Free(&Walker->Name);
     2416        Walker->Name = Malloc<char>(6, "molecule::CountAtoms: *walker->Name");
    24162417        sprintf(Walker->Name, "%2s%02d", Walker->type->symbol, Walker->nr+1);
    24172418        *out << "Naming atom nr. " << Walker->nr << " " << Walker->Name << "." << endl;
     
    26242625    NumberCells = divisor[0]*divisor[1]*divisor[2];
    26252626    *out << Verbose(1) << "Allocating " << NumberCells << " cells." << endl;
    2626     CellList = (molecule **) Malloc(sizeof(molecule *)*NumberCells, "molecule::CreateAdjacencyList - ** CellList");
     2627    CellList = Malloc<molecule*>(NumberCells, "molecule::CreateAdjacencyList - ** CellList");
    26272628    for (int i=NumberCells;i--;)
    26282629      CellList[i] = NULL;
     
    27062707        delete(CellList[i]);
    27072708      }
    2708     Free((void **)&CellList, "molecule::CreateAdjacencyList - ** CellList");
     2709    Free(&CellList);
    27092710
    27102711    // create the adjacency list per atom
     
    27712772    *out << Verbose(1) << "AtomCount is " << AtomCount << ", thus no bonds, no connections!." << endl;
    27722773  *out << Verbose(0) << "End of CreateAdjacencyList." << endl;
    2773   Free((void **)&matrix, "molecule::CreateAdjacencyList: *matrix");
     2774  Free(&matrix);
    27742775
    27752776};
     
    29812982void molecule::CyclicStructureAnalysis(ofstream *out, class StackClass<bond *> *  BackEdgeStack, int *&MinimumRingSize)
    29822983{
    2983   atom **PredecessorList = (atom **) Malloc(sizeof(atom *)*AtomCount, "molecule::CyclicStructureAnalysis: **PredecessorList");
    2984   int *ShortestPathList = (int *) Malloc(sizeof(int)*AtomCount, "molecule::CyclicStructureAnalysis: *ShortestPathList");
    2985   enum Shading *ColorList = (enum Shading *) Malloc(sizeof(enum Shading)*AtomCount, "molecule::CyclicStructureAnalysis: *ColorList");
     2984  atom **PredecessorList = Malloc<atom*>(AtomCount, "molecule::CyclicStructureAnalysis: **PredecessorList");
     2985  int *ShortestPathList = Malloc<int>(AtomCount, "molecule::CyclicStructureAnalysis: *ShortestPathList");
     2986  enum Shading *ColorList = Malloc<enum Shading>(AtomCount, "molecule::CyclicStructureAnalysis: *ColorList");
    29862987  class StackClass<atom *> *BFSStack = new StackClass<atom *> (AtomCount);   // will hold the current ring
    29872988  class StackClass<atom *> *TouchedStack = new StackClass<atom *> (AtomCount);   // contains all "touched" atoms (that need to be reset after BFS loop)
     
    31743175    *out << Verbose(1) << "No rings were detected in the molecular structure." << endl;
    31753176
    3176   Free((void **)&PredecessorList, "molecule::CyclicStructureAnalysis: **PredecessorList");
    3177   Free((void **)&ShortestPathList, "molecule::CyclicStructureAnalysis: **ShortestPathList");
    3178   Free((void **)&ColorList, "molecule::CyclicStructureAnalysis: **ColorList");
     3177  Free(&PredecessorList);
     3178  Free(&ShortestPathList);
     3179  Free(&ColorList);
    31793180  delete(BFSStack);
    31803181};
     
    32203221    Walker = Walker->next;
    32213222    if (Walker->ComponentNr != NULL)
    3222       Free((void **)&Walker->ComponentNr, "molecule::InitComponentNumbers: **Walker->ComponentNr");
    3223     Walker->ComponentNr = (int *) Malloc(sizeof(int)*NumberOfBondsPerAtom[Walker->nr], "molecule::InitComponentNumbers: *Walker->ComponentNr");
     3223      Free(&Walker->ComponentNr);
     3224    Walker->ComponentNr = Malloc<int>(NumberOfBondsPerAtom[Walker->nr], "molecule::InitComponentNumbers: *Walker->ComponentNr");
    32243225    for (int i=NumberOfBondsPerAtom[Walker->nr];i--;)
    32253226      Walker->ComponentNr[i] = -1;
     
    33443345  int NumberOfFragments = 0;
    33453346  double TEFactor;
    3346   char *filename = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::ParseKeySetFile - filename");
     3347  char *filename = Malloc<char>(MAXSTRINGSIZE, "molecule::ParseKeySetFile - filename");
    33473348
    33483349  if (FragmentList == NULL) { // check list pointer
     
    33563357  if (InputFile != NULL) {
    33573358    // each line represents a new fragment
    3358     char *buffer = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::ParseKeySetFile - *buffer");
     3359    char *buffer = Malloc<char>(MAXSTRINGSIZE, "molecule::ParseKeySetFile - *buffer");
    33593360    // 1. parse keysets and insert into temp. graph
    33603361    while (!InputFile.eof()) {
     
    33713372    InputFile.close();
    33723373    InputFile.clear();
    3373     Free((void **)&buffer, "molecule::ParseKeySetFile - *buffer");
     3374    Free(&buffer);
    33743375    *out << Verbose(1) << "done." << endl;
    33753376  } else {
     
    34043405
    34053406  // free memory
    3406   Free((void **)&filename, "molecule::ParseKeySetFile - filename");
     3407  Free(&filename);
    34073408
    34083409  return status;
     
    35113512  stringstream filename;
    35123513  bool status = true;
    3513   char *buffer = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::CheckAdjacencyFileAgainstMolecule: *buffer");
     3514  char *buffer = Malloc<char>(MAXSTRINGSIZE, "molecule::CheckAdjacencyFileAgainstMolecule: *buffer");
    35143515
    35153516  filename << path << "/" << FRAGMENTPREFIX << ADJACENCYFILE;
     
    35193520    // allocate storage structure
    35203521    int NonMatchNumber = 0;   // will number of atoms with differing bond structure
    3521     int *CurrentBonds = (int *) Malloc(sizeof(int)*8, "molecule::CheckAdjacencyFileAgainstMolecule - CurrentBonds"); // contains parsed bonds of current atom
     3522    int *CurrentBonds = Malloc<int>(8, "molecule::CheckAdjacencyFileAgainstMolecule - CurrentBonds"); // contains parsed bonds of current atom
    35223523    int CurrentBondsOfAtom;
    35233524
     
    35643565    } else
    35653566      *out << Verbose(1) << "done: Not equal by " << NonMatchNumber << " atoms." << endl;
    3566     Free((void **)&CurrentBonds, "molecule::CheckAdjacencyFileAgainstMolecule - **CurrentBonds");
     3567    Free(&CurrentBonds);
    35673568  } else {
    35683569    *out << Verbose(1) << "Adjacency file not found." << endl;
     
    35703571  }
    35713572  *out << endl;
    3572   Free((void **)&buffer, "molecule::CheckAdjacencyFileAgainstMolecule: *buffer");
     3573  Free(&buffer);
    35733574
    35743575  return status;
     
    35983599      return false;
    35993600    // parse the EnergyPerFragment file
    3600     char *buffer = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "molecule::CheckOrderAtSite: *buffer");
     3601    char *buffer = Malloc<char>(MAXSTRINGSIZE, "molecule::CheckOrderAtSite: *buffer");
    36013602    sprintf(buffer, "%s/%s%s.dat", path, FRAGMENTPREFIX, ENERGYPERFRAGMENT);
    36023603    InputFile.open(buffer, ios::in);
     
    37053706      }
    37063707    }
    3707     Free((void **)&buffer, "molecule::CheckOrderAtSite: *buffer");
     3708    Free(&buffer);
    37083709    // pick a given number of highest values and set AtomMask
    37093710  } else { // global increase of Bond Order
     
    37573758    return false;
    37583759  }
    3759   SortIndex = (int *) Malloc(sizeof(int)*AtomCount, "molecule::FragmentMolecule: *SortIndex");
     3760  SortIndex = Malloc<int>(AtomCount, "molecule::FragmentMolecule: *SortIndex");
    37603761  for(int i=AtomCount;i--;)
    37613762    SortIndex[i] = -1;
     
    38313832  // === compare it with adjacency file ===
    38323833  FragmentationToDo = FragmentationToDo && CheckAdjacencyFileAgainstMolecule(out, configuration->configpath, ListOfAtoms);
    3833   Free((void **)&ListOfAtoms, "molecule::FragmentMolecule - **ListOfAtoms");
     3834  Free(&ListOfAtoms);
    38343835
    38353836  // ===== 2. perform a DFS analysis to gather info on cyclic structure and a list of disconnected subgraphs =====
     
    39203921    delete(Subgraphs);
    39213922  }
    3922   Free((void **)&FragmentList, "molecule::FragmentMolecule - **FragmentList");
     3923  Free(&FragmentList);
    39233924
    39243925  // ===== 8b. gather keyset lists (graphs) from all subgraphs and transform into MoleculeListClass =====
     
    39673968      *out << Verbose(1) << "Freeing bond memory" << endl;
    39683969      delete(FragmentList); // remove bond molecule from memory
    3969       Free((void **)&SortIndex, "molecule::FragmentMolecule: *SortIndex");
     3970      Free(&SortIndex);
    39703971    } else
    39713972      *out << Verbose(1) << "FragmentList is zero on return, splitting failed." << endl;
     
    40554056bool molecule::ParseOrderAtSiteFromFile(ofstream *out, char *path)
    40564057{
    4057   unsigned char *OrderArray = (unsigned char *) Malloc(sizeof(unsigned char)*AtomCount, "molecule::ParseOrderAtSiteFromFile - *OrderArray");
    4058   bool *MaxArray = (bool *) Malloc(sizeof(bool)*AtomCount, "molecule::ParseOrderAtSiteFromFile - *MaxArray");
     4058  unsigned char *OrderArray = Malloc<unsigned char>(AtomCount, "molecule::ParseOrderAtSiteFromFile - *OrderArray");
     4059  bool *MaxArray = Malloc<bool>(AtomCount, "molecule::ParseOrderAtSiteFromFile - *MaxArray");
    40594060  bool status;
    40604061  int AtomNr, value;
     
    40974098    status = false;
    40984099  }
    4099   Free((void **)&OrderArray, "molecule::ParseOrderAtSiteFromFile - *OrderArray");
    4100   Free((void **)&MaxArray, "molecule::ParseOrderAtSiteFromFile - *MaxArray");
     4100  Free(&OrderArray);
     4101  Free(&MaxArray);
    41014102
    41024103  *out << Verbose(1) << "End of ParseOrderAtSiteFromFile" << endl;
     
    41214122  if (ListOfBondsPerAtom != NULL) {
    41224123    for(int i=AtomCount;i--;)
    4123       Free((void **)&ListOfBondsPerAtom[i], "molecule::CreateListOfBondsPerAtom: ListOfBondsPerAtom[i]");
    4124     Free((void **)&ListOfBondsPerAtom, "molecule::CreateListOfBondsPerAtom: ListOfBondsPerAtom");
     4124      Free(&ListOfBondsPerAtom[i]);
     4125    Free(&ListOfBondsPerAtom);
    41254126  }
    41264127  if (NumberOfBondsPerAtom != NULL)
    4127     Free((void **)&NumberOfBondsPerAtom, "molecule::CreateListOfBondsPerAtom: NumberOfBondsPerAtom");
    4128   ListOfBondsPerAtom = (bond ***) Malloc(sizeof(bond **)*AtomCount, "molecule::CreateListOfBondsPerAtom: ***ListOfBondsPerAtom");
    4129   NumberOfBondsPerAtom = (int *) Malloc(sizeof(int)*AtomCount, "molecule::CreateListOfBondsPerAtom: *NumberOfBondsPerAtom");
     4128    Free(&NumberOfBondsPerAtom);
     4129  ListOfBondsPerAtom = Malloc<bond**>(AtomCount, "molecule::CreateListOfBondsPerAtom: ***ListOfBondsPerAtom");
     4130  NumberOfBondsPerAtom = Malloc<int>(AtomCount, "molecule::CreateListOfBondsPerAtom: *NumberOfBondsPerAtom");
    41304131
    41314132  // reset bond counts per atom
     
    41414142  for(int i=AtomCount;i--;) {
    41424143    // allocate list of bonds per atom
    4143     ListOfBondsPerAtom[i] = (bond **) Malloc(sizeof(bond *)*NumberOfBondsPerAtom[i], "molecule::CreateListOfBondsPerAtom: **ListOfBondsPerAtom[]");
     4144    ListOfBondsPerAtom[i] = Malloc<bond*>(NumberOfBondsPerAtom[i], "molecule::CreateListOfBondsPerAtom: **ListOfBondsPerAtom[]");
    41444145    // clear the list again, now each NumberOfBondsPerAtom marks current free field
    41454146    NumberOfBondsPerAtom[i] = 0;
     
    41834184void molecule::BreadthFirstSearchAdd(ofstream *out, molecule *Mol, atom **&AddedAtomList, bond **&AddedBondList, atom *Root, bond *Bond, int BondOrder, bool IsAngstroem)
    41844185{
    4185   atom **PredecessorList = (atom **) Malloc(sizeof(atom *)*AtomCount, "molecule::BreadthFirstSearchAdd: **PredecessorList");
    4186   int *ShortestPathList = (int *) Malloc(sizeof(int)*AtomCount, "molecule::BreadthFirstSearchAdd: *ShortestPathList");
    4187   enum Shading *ColorList = (enum Shading *) Malloc(sizeof(enum Shading)*AtomCount, "molecule::BreadthFirstSearchAdd: *ColorList");
     4186  atom **PredecessorList = Malloc<atom*>(AtomCount, "molecule::BreadthFirstSearchAdd: **PredecessorList");
     4187  int *ShortestPathList = Malloc<int>(AtomCount, "molecule::BreadthFirstSearchAdd: *ShortestPathList");
     4188  enum Shading *ColorList = Malloc<enum Shading>(AtomCount, "molecule::BreadthFirstSearchAdd: *ColorList");
    41884189  class StackClass<atom *> *AtomStack = new StackClass<atom *>(AtomCount);
    41894190  atom *Walker = NULL, *OtherAtom = NULL;
     
    42904291    *out << Verbose(1) << "Coloring Walker " << Walker->Name << " black." << endl;
    42914292  }
    4292   Free((void **)&PredecessorList, "molecule::BreadthFirstSearchAdd: **PredecessorList");
    4293   Free((void **)&ShortestPathList, "molecule::BreadthFirstSearchAdd: **ShortestPathList");
    4294   Free((void **)&ColorList, "molecule::BreadthFirstSearchAdd: **ColorList");
     4293  Free(&PredecessorList);
     4294  Free(&ShortestPathList);
     4295  Free(&ColorList);
    42954296  delete(AtomStack);
    42964297};
     
    43094310  atom *Walker = NULL, *OtherAtom = NULL;
    43104311  bool status = true;
    4311   atom **ParentList = (atom **) Malloc(sizeof(atom *)*Father->AtomCount, "molecule::BuildInducedSubgraph: **ParentList");
     4312  atom **ParentList = Malloc<atom*>(Father->AtomCount, "molecule::BuildInducedSubgraph: **ParentList");
    43124313
    43134314  *out << Verbose(2) << "Begin of BuildInducedSubgraph." << endl;
     
    43484349  }
    43494350
    4350   Free((void **)&ParentList, "molecule::BuildInducedSubgraph: **ParentList");
     4351  Free(&ParentList);
    43514352  *out << Verbose(2) << "End of BuildInducedSubgraph." << endl;
    43524353  return status;
     
    43914392{
    43924393  atom *Runner = NULL, *FatherOfRunner = NULL, *OtherFather = NULL;
    4393   atom **SonList = (atom **) Malloc(sizeof(atom *)*AtomCount, "molecule::StoreFragmentFromStack: **SonList");
     4394  atom **SonList = Malloc<atom*>(AtomCount, "molecule::StoreFragmentFromStack: **SonList");
    43944395  molecule *Leaf = new molecule(elemente);
    43954396  bool LonelyFlag = false;
     
    44614462  Leaf->CreateListOfBondsPerAtom(out);
    44624463  //Leaflet->Leaf->ScanForPeriodicCorrection(out);
    4463   Free((void **)&SonList, "molecule::StoreFragmentFromStack: **SonList");
     4464  Free(&SonList);
    44644465//  *out << Verbose(1) << "End of StoreFragmentFromKeyset." << endl;
    44654466  return Leaf;
     
    44824483MoleculeListClass * molecule::CreateListOfUniqueFragmentsOfOrder(ofstream *out, int Order, config *configuration)
    44834484{
    4484   atom **PredecessorList = (atom **) Malloc(sizeof(atom *)*AtomCount, "molecule::CreateListOfUniqueFragmentsOfOrder: **PredecessorList");
    4485   int *ShortestPathList = (int *) Malloc(sizeof(int)*AtomCount, "molecule::CreateListOfUniqueFragmentsOfOrder: *ShortestPathList");
    4486   int *Labels = (int *) Malloc(sizeof(int)*AtomCount, "molecule::CreateListOfUniqueFragmentsOfOrder: *Labels");
    4487   enum Shading *ColorVertexList = (enum Shading *) Malloc(sizeof(enum Shading)*AtomCount, "molecule::CreateListOfUniqueFragmentsOfOrder: *ColorList");
    4488   enum Shading *ColorEdgeList = (enum Shading *) Malloc(sizeof(enum Shading)*BondCount, "molecule::CreateListOfUniqueFragmentsOfOrder: *ColorBondList");
     4485  atom **PredecessorList = Malloc<atom*>(AtomCount, "molecule::CreateListOfUniqueFragmentsOfOrder: **PredecessorList");
     4486  int *ShortestPathList = Malloc<int>(AtomCount, "molecule::CreateListOfUniqueFragmentsOfOrder: *ShortestPathList");
     4487  int *Labels = Malloc<int>(AtomCount, "molecule::CreateListOfUniqueFragmentsOfOrder: *Labels");
     4488  enum Shading *ColorVertexList = Malloc<enum Shading>(AtomCount, "molecule::CreateListOfUniqueFragmentsOfOrder: *ColorList");
     4489  enum Shading *ColorEdgeList = Malloc<enum Shading>(BondCount, "molecule::CreateListOfUniqueFragmentsOfOrder: *ColorBondList");
    44894490  StackClass<atom *> *RootStack = new StackClass<atom *>(AtomCount);
    44904491  StackClass<atom *> *TouchedStack = new StackClass<atom *>((int)pow(4,Order)+2); // number of atoms reached from one with maximal 4 bonds plus Root itself
     
    46164617
    46174618  // free memory and exit
    4618   Free((void **)&PredecessorList, "molecule::CreateListOfUniqueFragmentsOfOrder: **PredecessorList");
    4619   Free((void **)&ShortestPathList, "molecule::CreateListOfUniqueFragmentsOfOrder: *ShortestPathList");
    4620   Free((void **)&Labels, "molecule::CreateListOfUniqueFragmentsOfOrder: *Labels");
    4621   Free((void **)&ColorVertexList, "molecule::CreateListOfUniqueFragmentsOfOrder: *ColorList");
     4619  Free(&PredecessorList);
     4620  Free(&ShortestPathList);
     4621  Free(&Labels);
     4622  Free(&ColorVertexList);
    46224623  delete(RootStack);
    46234624  delete(TouchedStack);
     
    46694670  int Removal;
    46704671  int SpaceLeft;
    4671   int *TouchedList = (int *) Malloc(sizeof(int)*(SubOrder+1), "molecule::SPFragmentGenerator: *TouchedList");
     4672  int *TouchedList = Malloc<int>(SubOrder + 1, "molecule::SPFragmentGenerator: *TouchedList");
    46724673  bond *Binder = NULL;
    46734674  bond **BondsList = NULL;
     
    46774678
    46784679  // Hier muessen von 1 bis NumberOfBondsPerAtom[Walker->nr] alle Kombinationen
    4679   // von Endstuecken (aus den Bonds) hinzugefᅵᅵgt werden und fᅵᅵr verbleibende ANOVAOrder
    4680   // rekursiv GraphCrawler in der nᅵᅵchsten Ebene aufgerufen werden
     4680  // von Endstuecken (aus den Bonds) hinzugefuegt werden und fuer verbleibende ANOVAOrder
     4681  // rekursiv GraphCrawler in der naechsten Ebene aufgerufen werden
    46814682
    46824683  *out << Verbose(1+verbosity) << "Begin of SPFragmentGenerator." << endl;
     
    47384739          }
    47394740          // then allocate and fill the list
    4740           BondsList = (bond **) Malloc(sizeof(bond *)*SubSetDimension, "molecule::SPFragmentGenerator: **BondsList");
     4741          BondsList = Malloc<bond*>(SubSetDimension, "molecule::SPFragmentGenerator: **BondsList");
    47414742          SubSetDimension = 0;
    47424743          Binder = FragmentSearch->BondsPerSPList[2*SP];
     
    47504751          *out << Verbose(2+verbosity) << "Calling subset generator " << SP << " away from root " << *FragmentSearch->Root << " with sub set dimension " << SubSetDimension << "." << endl;
    47514752          SPFragmentGenerator(out, FragmentSearch, SP, BondsList, SubSetDimension, SubOrder-bits);
    4752           Free((void **)&BondsList, "molecule::SPFragmentGenerator: **BondsList");
     4753          Free(&BondsList);
    47534754        }
    47544755      } else {
     
    47844785    }
    47854786  }
    4786   Free((void **)&TouchedList, "molecule::SPFragmentGenerator: *TouchedList");
     4787  Free(&TouchedList);
    47874788  *out << Verbose(1+verbosity) << "End of SPFragmentGenerator, " << RootDistance << " away from Root " << *FragmentSearch->Root << " and SubOrder is " << SubOrder << "." << endl;
    47884789};
     
    49624963    *out << Verbose(0) << "Preparing subset for this root and calling generator." << endl;
    49634964    // prepare the subset and call the generator
    4964     BondsList = (bond **) Malloc(sizeof(bond *)*FragmentSearch.BondsPerSPCount[0], "molecule::PowerSetGenerator: **BondsList");
     4965    BondsList = Malloc<bond*>(FragmentSearch.BondsPerSPCount[0], "molecule::PowerSetGenerator: **BondsList");
    49654966    BondsList[0] = FragmentSearch.BondsPerSPList[0]->next;  // on SP level 0 there's only the root bond
    49664967
    49674968    SPFragmentGenerator(out, &FragmentSearch, 0, BondsList, FragmentSearch.BondsPerSPCount[0], Order);
    49684969
    4969     Free((void **)&BondsList, "molecule::PowerSetGenerator: **BondsList");
     4970    Free(&BondsList);
    49704971  } else {
    49714972    *out << Verbose(0) << "Not enough total number of edges to build " << Order << "-body fragments." << endl;
     
    50215022  *out << Verbose(2) << "Begin of ScanForPeriodicCorrection." << endl;
    50225023
    5023   ColorList = (enum Shading *) Malloc(sizeof(enum Shading)*AtomCount, "molecule::ScanForPeriodicCorrection: *ColorList");
     5024  ColorList = Malloc<enum Shading>(AtomCount, "molecule::ScanForPeriodicCorrection: *ColorList");
    50245025  while (flag) {
    50255026    // remove bonds that are beyond bonddistance
     
    50825083  // free allocated space from ReturnFullMatrixforSymmetric()
    50835084  delete(AtomStack);
    5084   Free((void **)&ColorList, "molecule::ScanForPeriodicCorrection: *ColorList");
    5085   Free((void **)&matrix, "molecule::ScanForPeriodicCorrection: *matrix");
     5085  Free(&ColorList);
     5086  Free(&matrix);
    50865087  *out << Verbose(2) << "End of ScanForPeriodicCorrection." << endl;
    50875088};
     
    50935094double * molecule::ReturnFullMatrixforSymmetric(double *symm)
    50945095{
    5095   double *matrix = (double *) Malloc(sizeof(double)*NDIM*NDIM, "molecule::ReturnFullMatrixforSymmetric: *matrix");
     5096  double *matrix = Malloc<double>(NDIM * NDIM, "molecule::ReturnFullMatrixforSymmetric: *matrix");
    50965097  matrix[0] = symm[0];
    50975098  matrix[1] = symm[1];
     
    52205221  // FragmentLowerOrdersList is a 2D-array of pointer to MoleculeListClass objects, one dimension represents the ANOVA expansion of a single order (i.e. 5)
    52215222  // with all needed lower orders that are subtracted, the other dimension is the BondOrder (i.e. from 1 to 5)
    5222   NumMoleculesOfOrder = (int *) Malloc(sizeof(int)*UpgradeCount, "molecule::FragmentBOSSANOVA: *NumMoleculesOfOrder");
    5223   FragmentLowerOrdersList = (Graph ***) Malloc(sizeof(Graph **)*UpgradeCount, "molecule::FragmentBOSSANOVA: ***FragmentLowerOrdersList");
     5223  NumMoleculesOfOrder = Malloc<int>(UpgradeCount, "molecule::FragmentBOSSANOVA: *NumMoleculesOfOrder");
     5224  FragmentLowerOrdersList = Malloc<Graph**>(UpgradeCount, "molecule::FragmentBOSSANOVA: ***FragmentLowerOrdersList");
    52245225
    52255226  // initialise the fragments structure
    5226   FragmentSearch.ShortestPathList = (int *) Malloc(sizeof(int)*AtomCount, "molecule::PowerSetGenerator: *ShortestPathList");
     5227  FragmentSearch.ShortestPathList = Malloc<int>(AtomCount, "molecule::PowerSetGenerator: *ShortestPathList");
    52275228  FragmentSearch.FragmentCounter = 0;
    52285229  FragmentSearch.FragmentSet = new KeySet;
     
    52595260
    52605261      // initialise Order-dependent entries of UniqueFragments structure
    5261       FragmentSearch.BondsPerSPList = (bond **) Malloc(sizeof(bond *)*Order*2, "molecule::PowerSetGenerator: ***BondsPerSPList");
    5262       FragmentSearch.BondsPerSPCount = (int *) Malloc(sizeof(int)*Order, "molecule::PowerSetGenerator: *BondsPerSPCount");
     5262      FragmentSearch.BondsPerSPList = Malloc<bond*>(Order * 2, "molecule::PowerSetGenerator: ***BondsPerSPList");
     5263      FragmentSearch.BondsPerSPCount = Malloc<int>(Order, "molecule::PowerSetGenerator: *BondsPerSPCount");
    52635264      for (int i=Order;i--;) {
    52645265        FragmentSearch.BondsPerSPList[2*i] = new bond();    // start node
     
    52715272      // allocate memory for all lower level orders in this 1D-array of ptrs
    52725273      NumLevels = 1 << (Order-1); // (int)pow(2,Order);
    5273       FragmentLowerOrdersList[RootNr] = (Graph **) Malloc(sizeof(Graph *)*NumLevels, "molecule::FragmentBOSSANOVA: **FragmentLowerOrdersList[]");
     5274      FragmentLowerOrdersList[RootNr] = Malloc<Graph*>(NumLevels, "molecule::FragmentBOSSANOVA: **FragmentLowerOrdersList[]");
    52745275      for (int i=0;i<NumLevels;i++)
    52755276        FragmentLowerOrdersList[RootNr][i] = NULL;
     
    53385339
    53395340      // free Order-dependent entries of UniqueFragments structure for next loop cycle
    5340       Free((void **)&FragmentSearch.BondsPerSPCount, "molecule::PowerSetGenerator: *BondsPerSPCount");
     5341      Free(&FragmentSearch.BondsPerSPCount);
    53415342      for (int i=Order;i--;) {
    53425343        delete(FragmentSearch.BondsPerSPList[2*i]);
    53435344        delete(FragmentSearch.BondsPerSPList[2*i+1]);
    53445345      }
    5345       Free((void **)&FragmentSearch.BondsPerSPList, "molecule::PowerSetGenerator: ***BondsPerSPList");
     5346      Free(&FragmentSearch.BondsPerSPList);
    53465347    }
    53475348  }
     
    53515352
    53525353  // cleanup FragmentSearch structure
    5353   Free((void **)&FragmentSearch.ShortestPathList, "molecule::PowerSetGenerator: *ShortestPathList");
     5354  Free(&FragmentSearch.ShortestPathList);
    53545355  delete(FragmentSearch.FragmentSet);
    53555356
     
    53825383      }
    53835384    }
    5384     Free((void **)&FragmentLowerOrdersList[RootNr], "molecule::FragmentBOSSANOVA: **FragmentLowerOrdersList[]");
     5385    Free(&FragmentLowerOrdersList[RootNr]);
    53855386    RootNr++;
    53865387  }
    5387   Free((void **)&FragmentLowerOrdersList, "molecule::FragmentBOSSANOVA: ***FragmentLowerOrdersList");
    5388   Free((void **)&NumMoleculesOfOrder, "molecule::FragmentBOSSANOVA: *NumMoleculesOfOrder");
     5388  Free(&FragmentLowerOrdersList);
     5389  Free(&NumMoleculesOfOrder);
    53895390
    53905391  *out << Verbose(0) << "End of FragmentBOSSANOVA." << endl;
     
    54765477  if (result) {
    54775478    *out << Verbose(5) << "Calculating distances" << endl;
    5478     Distances = (double *) Malloc(sizeof(double)*AtomCount, "molecule::IsEqualToWithinThreshold: Distances");
    5479     OtherDistances = (double *) Malloc(sizeof(double)*AtomCount, "molecule::IsEqualToWithinThreshold: OtherDistances");
     5479    Distances = Malloc<double>(AtomCount, "molecule::IsEqualToWithinThreshold: Distances");
     5480    OtherDistances = Malloc<double>(AtomCount, "molecule::IsEqualToWithinThreshold: OtherDistances");
    54805481    Walker = start;
    54815482    while (Walker->next != end) {
     
    54915492    /// ... sort each list (using heapsort (o(N log N)) from GSL)
    54925493    *out << Verbose(5) << "Sorting distances" << endl;
    5493     PermMap = (size_t *) Malloc(sizeof(size_t)*AtomCount, "molecule::IsEqualToWithinThreshold: *PermMap");
    5494     OtherPermMap = (size_t *) Malloc(sizeof(size_t)*AtomCount, "molecule::IsEqualToWithinThreshold: *OtherPermMap");
     5494    PermMap = Malloc<size_t>(AtomCount, "molecule::IsEqualToWithinThreshold: *PermMap");
     5495    OtherPermMap = Malloc<size_t>(AtomCount, "molecule::IsEqualToWithinThreshold: *OtherPermMap");
    54955496    gsl_heapsort_index (PermMap, Distances, AtomCount, sizeof(double), CompareDoubles);
    54965497    gsl_heapsort_index (OtherPermMap, OtherDistances, AtomCount, sizeof(double), CompareDoubles);
    5497     PermutationMap = (int *) Malloc(sizeof(int)*AtomCount, "molecule::IsEqualToWithinThreshold: *PermutationMap");
     5498    PermutationMap = Malloc<int>(AtomCount, "molecule::IsEqualToWithinThreshold: *PermutationMap");
    54985499    *out << Verbose(5) << "Combining Permutation Maps" << endl;
    54995500    for(int i=AtomCount;i--;)
    55005501      PermutationMap[PermMap[i]] = (int) OtherPermMap[i];
    55015502
    5502     /// ... and compare them step by step, whether the difference is individiually(!) below \a threshold for all
     5503    /// ... and compare them step by step, whether the difference is individually(!) below \a threshold for all
    55035504    *out << Verbose(4) << "Comparing distances" << endl;
    55045505    flag = 0;
     
    55085509        flag = 1;
    55095510    }
    5510     Free((void **)&PermMap, "molecule::IsEqualToWithinThreshold: *PermMap");
    5511     Free((void **)&OtherPermMap, "molecule::IsEqualToWithinThreshold: *OtherPermMap");
    5512 
    5513     /// free memory
    5514     Free((void **)&Distances, "molecule::IsEqualToWithinThreshold: Distances");
    5515     Free((void **)&OtherDistances, "molecule::IsEqualToWithinThreshold: OtherDistances");
     5511
     5512    // free memory
     5513    Free(&PermMap);
     5514    Free(&OtherPermMap);
     5515    Free(&Distances);
     5516    Free(&OtherDistances);
    55165517    if (flag) { // if not equal
    5517       Free((void **)&PermutationMap, "molecule::IsEqualToWithinThreshold: *PermutationMap");
     5518      Free(&PermutationMap);
    55185519      result = false;
    55195520    }
     
    55415542  atom *Walker = NULL, *OtherWalker = NULL;
    55425543  *out << Verbose(3) << "Begin of GetFatherAtomicMap." << endl;
    5543   int *AtomicMap = (int *) Malloc(sizeof(int)*AtomCount, "molecule::GetAtomicMap: *AtomicMap");  //Calloc
     5544  int *AtomicMap = Malloc<int>(AtomCount, "molecule::GetAtomicMap: *AtomicMap");
    55445545  for (int i=AtomCount;i--;)
    55455546    AtomicMap[i] = -1;
  • src/parser.cpp

    r89c8b2 r29812d  
    88
    99#include "helpers.hpp"
     10#include "memoryallocator.hpp"
    1011#include "parser.hpp"
    1112
     
    5657MatrixContainer::MatrixContainer() {
    5758  Indices = NULL;
    58   Header = (char **) Malloc(sizeof(char)*1, "MatrixContainer::MatrixContainer: **Header");
    59   Matrix = (double ***) Malloc(sizeof(double **)*(1), "MatrixContainer::MatrixContainer: ***Matrix"); // one more each for the total molecule
    60   RowCounter = (int *) Malloc(sizeof(int)*(1), "MatrixContainer::MatrixContainer: *RowCounter");
    61   ColumnCounter = (int *) Malloc(sizeof(int)*(1), "MatrixContainer::MatrixContainer: *ColumnCounter");
     59  Header = Malloc<char*>(1, "MatrixContainer::MatrixContainer: **Header");
     60  Matrix = Malloc<double**>(1, "MatrixContainer::MatrixContainer: ***Matrix"); // one more each for the total molecule
     61  RowCounter = Malloc<int>(1, "MatrixContainer::MatrixContainer: *RowCounter");
     62  ColumnCounter = Malloc<int>(1, "MatrixContainer::MatrixContainer: *ColumnCounter");
    6263  Header[0] = NULL;
    6364  Matrix[0] = NULL;
     
    7475      if ((ColumnCounter != NULL) && (RowCounter != NULL)) {
    7576          for(int j=RowCounter[i]+1;j--;)
    76             Free((void **)&Matrix[i][j], "MatrixContainer::~MatrixContainer: *Matrix[][]");
    77         Free((void **)&Matrix[i], "MatrixContainer::~MatrixContainer: **Matrix[]");
     77            Free(&Matrix[i][j]);
     78        Free(&Matrix[i]);
    7879      }
    7980    }
    8081    if ((ColumnCounter != NULL) && (RowCounter != NULL) && (Matrix[MatrixCounter] != NULL))
    8182      for(int j=RowCounter[MatrixCounter]+1;j--;)
    82         Free((void **)&Matrix[MatrixCounter][j], "MatrixContainer::~MatrixContainer: *Matrix[MatrixCounter][]");
     83        Free(&Matrix[MatrixCounter][j]);
    8384    if (MatrixCounter != 0)
    84       Free((void **)&Matrix[MatrixCounter], "MatrixContainer::~MatrixContainer: **Matrix[MatrixCounter]");
    85     Free((void **)&Matrix, "MatrixContainer::~MatrixContainer: ***Matrix");
     85      Free(&Matrix[MatrixCounter]);
     86    Free(&Matrix);
    8687  }
    8788  if (Indices != NULL)
    8889    for(int i=MatrixCounter+1;i--;) {
    89       Free((void **)&Indices[i], "MatrixContainer::~MatrixContainer: *Indices[]");
    90     }
    91   Free((void **)&Indices, "MatrixContainer::~MatrixContainer: **Indices");
     90      Free(&Indices[i]);
     91    }
     92  Free(&Indices);
    9293 
    9394  if (Header != NULL)
    9495    for(int i=MatrixCounter+1;i--;)
    95       Free((void **)&Header[i], "MatrixContainer::~MatrixContainer: *Header[]");
    96   Free((void **)&Header, "MatrixContainer::~MatrixContainer: **Header");
    97   Free((void **)&RowCounter, "MatrixContainer::~MatrixContainer: *RowCounter");
    98   Free((void **)&ColumnCounter, "MatrixContainer::~MatrixContainer: *RowCounter");
     96      Free(&Header[i]);
     97  Free(&Header);
     98  Free(&RowCounter);
     99  Free(&ColumnCounter);
    99100};
    100101
     
    109110  if (Matrix == NULL) {
    110111    cout << " with trivial mapping." << endl;
    111     Indices = (int **) Malloc(sizeof(int *)*(MatrixCounter+1), "MatrixContainer::InitialiseIndices: **Indices");
     112    Indices = Malloc<int*>(MatrixCounter + 1, "MatrixContainer::InitialiseIndices: **Indices");
    112113    for(int i=MatrixCounter+1;i--;) {
    113       Indices[i] = (int *) Malloc(sizeof(int)*RowCounter[i], "MatrixContainer::InitialiseIndices: *Indices[]");
     114      Indices[i] = Malloc<int>(RowCounter[i], "MatrixContainer::InitialiseIndices: *Indices[]");
    114115      for(int j=RowCounter[i];j--;)
    115116        Indices[i][j] = j;
     
    119120    if (MatrixCounter != Matrix->MatrixCounter)
    120121      return false;
    121     Indices = (int **) Malloc(sizeof(int *)*(MatrixCounter+1), "MatrixContainer::InitialiseIndices: **Indices");
     122    Indices = Malloc<int*>(MatrixCounter + 1, "MatrixContainer::InitialiseIndices: **Indices");
    122123    for(int i=MatrixCounter+1;i--;) {
    123124      if (RowCounter[i] != Matrix->RowCounter[i])
    124125        return false;
    125       Indices[i] = (int *) Malloc(sizeof(int)*Matrix->RowCounter[i], "MatrixContainer::InitialiseIndices: *Indices[]");
     126      Indices[i] = Malloc<int>(Matrix->RowCounter[i], "MatrixContainer::InitialiseIndices: *Indices[]");
    126127      for(int j=Matrix->RowCounter[i];j--;) {
    127128        Indices[i][j] = Matrix->Indices[i][j];
     
    162163
    163164  // parse header
    164   Header[MatrixNr] = (char *) Malloc(sizeof(char)*1024, "MatrixContainer::ParseMatrix: *Header[]");
     165  Header[MatrixNr] = Malloc<char>(1024, "MatrixContainer::ParseMatrix: *Header[]");
    165166  for (int m=skiplines+1;m--;)
    166167    input.getline(Header[MatrixNr], 1023);
     
    197198  // allocate matrix if it's not zero dimension in one direction
    198199  if ((ColumnCounter[MatrixNr] > 0) && (RowCounter[MatrixNr] > -1)) {
    199     Matrix[MatrixNr] = (double **) Malloc(sizeof(double *)*(RowCounter[MatrixNr]+1), "MatrixContainer::ParseMatrix: **Matrix[]");
     200    Matrix[MatrixNr] = Malloc<double*>(RowCounter[MatrixNr] + 1, "MatrixContainer::ParseMatrix: **Matrix[]");
    200201 
    201202    // parse in each entry for this matrix
     
    209210    strncpy(Header[MatrixNr], line.str().c_str(), 1023); 
    210211    for(int j=0;j<RowCounter[MatrixNr];j++) {
    211       Matrix[MatrixNr][j] = (double *) Malloc(sizeof(double)*ColumnCounter[MatrixNr], "MatrixContainer::ParseMatrix: *Matrix[][]");
     212      Matrix[MatrixNr][j] = Malloc<double>(ColumnCounter[MatrixNr], "MatrixContainer::ParseMatrix: *Matrix[][]");
    212213      input.getline(filename, 1023);
    213214      stringstream lines(filename);
     
    220221      }
    221222      //cout << endl;
    222       Matrix[MatrixNr][ RowCounter[MatrixNr] ] = (double *) Malloc(sizeof(double)*ColumnCounter[MatrixNr], "MatrixContainer::ParseMatrix: *Matrix[RowCounter[MatrixNr]][]");
     223      Matrix[MatrixNr][ RowCounter[MatrixNr] ] = Malloc<double>(ColumnCounter[MatrixNr], "MatrixContainer::ParseMatrix: *Matrix[RowCounter[MatrixNr]][]");
    223224      for(int j=ColumnCounter[MatrixNr];j--;)
    224225        Matrix[MatrixNr][ RowCounter[MatrixNr] ][j] = 0.;
     
    274275
    275276  cout << "Parsing through each fragment and retrieving " << prefix << suffix << "." << endl;
    276   Header = (char **) ReAlloc(Header, sizeof(char *)*(MatrixCounter+1), "MatrixContainer::ParseFragmentMatrix: **Header"); // one more each for the total molecule
    277   Matrix = (double ***) ReAlloc(Matrix, sizeof(double **)*(MatrixCounter+1), "MatrixContainer::ParseFragmentMatrix: ***Matrix"); // one more each for the total molecule
    278   RowCounter = (int *) ReAlloc(RowCounter, sizeof(int)*(MatrixCounter+1), "MatrixContainer::ParseFragmentMatrix: *RowCounter");
    279   ColumnCounter = (int *) ReAlloc(ColumnCounter, sizeof(int)*(MatrixCounter+1), "MatrixContainer::ParseFragmentMatrix: *ColumnCounter");
     277  Header = ReAlloc<char*>(Header, MatrixCounter + 1, "MatrixContainer::ParseFragmentMatrix: **Header"); // one more each for the total molecule
     278  Matrix = ReAlloc<double**>(Matrix, MatrixCounter + 1, "MatrixContainer::ParseFragmentMatrix: ***Matrix"); // one more each for the total molecule
     279  RowCounter = ReAlloc<int>(RowCounter, MatrixCounter + 1, "MatrixContainer::ParseFragmentMatrix: *RowCounter");
     280  ColumnCounter = ReAlloc<int>(ColumnCounter, MatrixCounter + 1, "MatrixContainer::ParseFragmentMatrix: *ColumnCounter");
    280281  for(int i=MatrixCounter+1;i--;) {
    281282    Matrix[i] = NULL;
     
    291292    if (!ParseMatrix(file.str().c_str(), skiplines, skipcolumns, i))
    292293      return false;
    293     Free((void **)&FragmentNumber, "MatrixContainer::ParseFragmentMatrix: *FragmentNumber");
     294    Free(&FragmentNumber);
    294295  }
    295296  return true;
     
    306307{
    307308  MatrixCounter = MCounter;
    308   Header = (char **) Malloc(sizeof(char *)*(MatrixCounter+1), "MatrixContainer::AllocateMatrix: *Header");
    309   Matrix = (double ***) Malloc(sizeof(double **)*(MatrixCounter+1), "MatrixContainer::AllocateMatrix: ***Matrix"); // one more each for the total molecule
    310   RowCounter = (int *) Malloc(sizeof(int)*(MatrixCounter+1), "MatrixContainer::AllocateMatrix: *RowCounter");
    311   ColumnCounter = (int *) Malloc(sizeof(int)*(MatrixCounter+1), "MatrixContainer::AllocateMatrix: *ColumnCounter");
     309  Header = Malloc<char*>(MatrixCounter + 1, "MatrixContainer::AllocateMatrix: *Header");
     310  Matrix = Malloc<double**>(MatrixCounter + 1, "MatrixContainer::AllocateMatrix: ***Matrix"); // one more each for the total molecule
     311  RowCounter = Malloc<int>(MatrixCounter + 1, "MatrixContainer::AllocateMatrix: *RowCounter");
     312  ColumnCounter = Malloc<int>(MatrixCounter + 1, "MatrixContainer::AllocateMatrix: *ColumnCounter");
    312313  for(int i=MatrixCounter+1;i--;) {
    313     Header[i] = (char *) Malloc(sizeof(char)*1024, "MatrixContainer::AllocateMatrix: *Header[i]");
     314    Header[i] = Malloc<char>(1024, "MatrixContainer::AllocateMatrix: *Header[i]");
    314315    strncpy(Header[i], GivenHeader[i], 1023);
    315316    RowCounter[i] = RCounter[i];
    316317    ColumnCounter[i] = CCounter[i];
    317     Matrix[i] = (double **) Malloc(sizeof(double *)*(RowCounter[i]+1), "MatrixContainer::AllocateMatrix: **Matrix[]"); 
     318    Matrix[i] = Malloc<double*>(RowCounter[i] + 1, "MatrixContainer::AllocateMatrix: **Matrix[]");
    318319    for(int j=RowCounter[i]+1;j--;) {
    319       Matrix[i][j] = (double *) Malloc(sizeof(double)*ColumnCounter[i], "MatrixContainer::AllocateMatrix: *Matrix[][]");
     320      Matrix[i][j] = Malloc<double>(ColumnCounter[i], "MatrixContainer::AllocateMatrix: *Matrix[][]");
    320321      for(int k=ColumnCounter[i];k--;)
    321322        Matrix[i][j][k] = 0.;
     
    466467    FragmentNumber = FixedDigitNumber(MatrixCounter, i);
    467468    line << name << FRAGMENTPREFIX << FragmentNumber << "/" << prefix;
    468     Free((void **)&FragmentNumber, "*FragmentNumber");
     469    Free(&FragmentNumber);
    469470    output.open(line.str().c_str(), ios::out);
    470471    if (output == NULL) {
     
    520521{
    521522  cout << "Parsing energy indices." << endl;
    522   Indices = (int **) Malloc(sizeof(int *)*(MatrixCounter+1), "EnergyMatrix::ParseIndices: **Indices");
     523  Indices = Malloc<int*>(MatrixCounter + 1, "EnergyMatrix::ParseIndices: **Indices");
    523524  for(int i=MatrixCounter+1;i--;) {
    524     Indices[i] = (int *) Malloc(sizeof(int)*RowCounter[i], "EnergyMatrix::ParseIndices: *Indices[]");
     525    Indices[i] = Malloc<int>(RowCounter[i], "EnergyMatrix::ParseIndices: *Indices[]");
    525526    for(int j=RowCounter[i];j--;)
    526527      Indices[i][j] = j;
     
    579580    // allocate last plus one matrix
    580581    cout << "Allocating last plus one matrix with " << (RowCounter[MatrixCounter]+1) << " rows and " << ColumnCounter[MatrixCounter] << " columns." << endl;
    581     Matrix[MatrixCounter] = (double **) Malloc(sizeof(double *)*(RowCounter[MatrixCounter]+1), "MatrixContainer::ParseFragmentMatrix: **Matrix[]");
     582    Matrix[MatrixCounter] = Malloc<double*>(RowCounter[MatrixCounter] + 1, "MatrixContainer::ParseFragmentMatrix: **Matrix[]");
    582583    for(int j=0;j<=RowCounter[MatrixCounter];j++)
    583       Matrix[MatrixCounter][j] = (double *) Malloc(sizeof(double)*ColumnCounter[MatrixCounter], "MatrixContainer::ParseFragmentMatrix: *Matrix[][]");
     584      Matrix[MatrixCounter][j] = Malloc<double>(ColumnCounter[MatrixCounter], "MatrixContainer::ParseFragmentMatrix: *Matrix[][]");
    584585   
    585586    // try independently to parse global energysuffix file if present
     
    606607
    607608  cout << "Parsing force indices for " << MatrixCounter << " matrices." << endl;
    608   Indices = (int **) Malloc(sizeof(int *)*(MatrixCounter+1), "ForceMatrix::ParseIndices: **Indices");
     609  Indices = Malloc<int*>(MatrixCounter + 1, "ForceMatrix::ParseIndices: **Indices");
    609610  line << name << FRAGMENTPREFIX << FORCESFILE;
    610611  input.open(line.str().c_str(), ios::in);
     
    619620    line.str(filename);
    620621    // parse the values
    621     Indices[i] = (int *) Malloc(sizeof(int)*RowCounter[i], "ForceMatrix::ParseIndices: *Indices[]");
     622    Indices[i] = Malloc<int>(RowCounter[i], "ForceMatrix::ParseIndices: *Indices[]");
    622623    FragmentNumber = FixedDigitNumber(MatrixCounter, i);
    623624    //cout << FRAGMENTPREFIX << FragmentNumber << "[" << RowCounter[i] << "]:";
    624     Free((void **)&FragmentNumber, "ForceMatrix::ParseIndices: *FragmentNumber");
     625    Free(&FragmentNumber);
    625626    for(int j=0;(j<RowCounter[i]) && (!line.eof());j++) {
    626627      line >> Indices[i][j];
     
    629630    //cout << endl;
    630631  }
    631   Indices[MatrixCounter] = (int *) Malloc(sizeof(int)*RowCounter[MatrixCounter], "ForceMatrix::ParseIndices: *Indices[]");
     632  Indices[MatrixCounter] = Malloc<int>(RowCounter[MatrixCounter], "ForceMatrix::ParseIndices: *Indices[]");
    632633  for(int j=RowCounter[MatrixCounter];j--;) {
    633634    Indices[MatrixCounter][j] = j;
     
    714715    // allocate last plus one matrix
    715716    cout << "Allocating last plus one matrix with " << (RowCounter[MatrixCounter]+1) << " rows and " << ColumnCounter[MatrixCounter] << " columns." << endl;
    716     Matrix[MatrixCounter] = (double **) Malloc(sizeof(double *)*(RowCounter[MatrixCounter]+1), "MatrixContainer::ParseFragmentMatrix: **Matrix[]");
     717    Matrix[MatrixCounter] = Malloc<double*>(RowCounter[MatrixCounter] + 1, "MatrixContainer::ParseFragmentMatrix: **Matrix[]");
    717718    for(int j=0;j<=RowCounter[MatrixCounter];j++)
    718       Matrix[MatrixCounter][j] = (double *) Malloc(sizeof(double)*ColumnCounter[MatrixCounter], "MatrixContainer::ParseFragmentMatrix: *Matrix[][]");
     719      Matrix[MatrixCounter][j] = Malloc<double>(ColumnCounter[MatrixCounter], "MatrixContainer::ParseFragmentMatrix: *Matrix[][]");
    719720
    720721    // try independently to parse global forcesuffix file if present
     
    743744 
    744745  cout << "Parsing hessian indices for " << MatrixCounter << " matrices." << endl;
    745   Indices = (int **) Malloc(sizeof(int *)*(MatrixCounter+1), "HessianMatrix::ParseIndices: **Indices");
     746  Indices = Malloc<int*>(MatrixCounter + 1, "HessianMatrix::ParseIndices: **Indices");
    746747  line << name << FRAGMENTPREFIX << FORCESFILE;
    747748  input.open(line.str().c_str(), ios::in);
     
    756757    line.str(filename);
    757758    // parse the values
    758     Indices[i] = (int *) Malloc(sizeof(int)*RowCounter[i], "HessianMatrix::ParseIndices: *Indices[]");
     759    Indices[i] = Malloc<int>(RowCounter[i], "HessianMatrix::ParseIndices: *Indices[]");
    759760    FragmentNumber = FixedDigitNumber(MatrixCounter, i);
    760761    //cout << FRAGMENTPREFIX << FragmentNumber << "[" << RowCounter[i] << "]:";
    761     Free((void **)&FragmentNumber, "HessianMatrix::ParseIndices: *FragmentNumber");
     762    Free(&FragmentNumber);
    762763    for(int j=0;(j<RowCounter[i]) && (!line.eof());j++) {
    763764      line >> Indices[i][j];
     
    766767    //cout << endl;
    767768  }
    768   Indices[MatrixCounter] = (int *) Malloc(sizeof(int)*RowCounter[MatrixCounter], "HessianMatrix::ParseIndices: *Indices[]");
     769  Indices[MatrixCounter] = Malloc<int>(RowCounter[MatrixCounter], "HessianMatrix::ParseIndices: *Indices[]");
    769770  for(int j=RowCounter[MatrixCounter];j--;) {
    770771    Indices[MatrixCounter][j] = j;
     
    938939    // allocate last plus one matrix
    939940    cout << "Allocating last plus one matrix with " << (RowCounter[MatrixCounter]+1) << " rows and " << ColumnCounter[MatrixCounter] << " columns." << endl;
    940     Matrix[MatrixCounter] = (double **) Malloc(sizeof(double *)*(RowCounter[MatrixCounter]+1), "MatrixContainer::ParseFragmentMatrix: **Matrix[]");
     941    Matrix[MatrixCounter] = Malloc<double*>(RowCounter[MatrixCounter] + 1, "MatrixContainer::ParseFragmentMatrix: **Matrix[]");
    941942    for(int j=0;j<=RowCounter[MatrixCounter];j++)
    942       Matrix[MatrixCounter][j] = (double *) Malloc(sizeof(double)*ColumnCounter[MatrixCounter], "MatrixContainer::ParseFragmentMatrix: *Matrix[][]");
     943      Matrix[MatrixCounter][j] = Malloc<double>(ColumnCounter[MatrixCounter], "MatrixContainer::ParseFragmentMatrix: *Matrix[][]");
    943944
    944945    // try independently to parse global forcesuffix file if present
     
    970971KeySetsContainer::~KeySetsContainer() {
    971972  for(int i=FragmentCounter;i--;)
    972     Free((void **)&KeySets[i], "KeySetsContainer::~KeySetsContainer: *KeySets[]");
     973    Free(&KeySets[i]);
    973974  for(int i=Order;i--;)
    974     Free((void **)&OrderSet[i], "KeySetsContainer::~KeySetsContainer: *OrderSet[]");
    975   Free((void **)&KeySets, "KeySetsContainer::~KeySetsContainer: **KeySets");
    976   Free((void **)&OrderSet, "KeySetsContainer::~KeySetsContainer: **OrderSet");
    977   Free((void **)&AtomCounter, "KeySetsContainer::~KeySetsContainer: *AtomCounter");
    978   Free((void **)&FragmentsPerOrder, "KeySetsContainer::~KeySetsContainer: *FragmentsPerOrder");
     975    Free(&OrderSet[i]);
     976  Free(&KeySets);
     977  Free(&OrderSet);
     978  Free(&AtomCounter);
     979  Free(&FragmentsPerOrder);
    979980};
    980981
     
    993994  FragmentCounter = FCounter;
    994995  cout << "Parsing key sets." << endl;
    995   KeySets = (int **) Malloc(sizeof(int *)*FragmentCounter, "KeySetsContainer::ParseKeySets: **KeySets");
     996  KeySets = Malloc<int*>(FragmentCounter, "KeySetsContainer::ParseKeySets: **KeySets");
    996997  for(int i=FragmentCounter;i--;)
    997998    KeySets[i] = NULL;
     
    10031004  }
    10041005
    1005   AtomCounter = (int *) Malloc(sizeof(int)*FragmentCounter, "KeySetsContainer::ParseKeySets: *RowCounter");
     1006  AtomCounter = Malloc<int>(FragmentCounter, "KeySetsContainer::ParseKeySets: *RowCounter");
    10061007  for(int i=0;(i<FragmentCounter) && (!input.eof());i++) {
    10071008    stringstream line;
    10081009    AtomCounter[i] = ACounter[i];
    10091010    // parse the values
    1010     KeySets[i] = (int *) Malloc(sizeof(int)*AtomCounter[i], "KeySetsContainer::ParseKeySets: *KeySets[]");
     1011    KeySets[i] = Malloc<int>(AtomCounter[i], "KeySetsContainer::ParseKeySets: *KeySets[]");
    10111012    for(int j=AtomCounter[i];j--;)
    10121013      KeySets[i][j] = -1;
    10131014    FragmentNumber = FixedDigitNumber(FragmentCounter, i);
    10141015    //cout << FRAGMENTPREFIX << FragmentNumber << "[" << AtomCounter[i] << "]:";
    1015     Free((void **)&FragmentNumber, "KeySetsContainer::ParseKeySets: *FragmentNumber");
     1016    Free(&FragmentNumber);
    10161017    input.getline(filename, 1023);
    10171018    line.str(filename);
     
    10471048
    10481049  // scan through all to determine fragments per order
    1049   FragmentsPerOrder = (int *) Malloc(sizeof(int)*Order, "KeySetsContainer::ParseManyBodyTerms: *FragmentsPerOrder");
     1050  FragmentsPerOrder = Malloc<int>(Order, "KeySetsContainer::ParseManyBodyTerms: *FragmentsPerOrder");
    10501051  for(int i=Order;i--;)
    10511052    FragmentsPerOrder[i] = 0;
     
    10611062
    10621063  // scan through all to gather indices to each order set
    1063   OrderSet = (int **) Malloc(sizeof(int *)*Order, "KeySetsContainer::ParseManyBodyTerms: **OrderSet");
     1064  OrderSet = Malloc<int*>(Order, "KeySetsContainer::ParseManyBodyTerms: **OrderSet");
    10641065  for(int i=Order;i--;)
    1065     OrderSet[i] = (int *) Malloc(sizeof(int)*FragmentsPerOrder[i], "KeySetsContainer::ParseManyBodyTermsKeySetsContainer::ParseManyBodyTerms: *OrderSet[]");
     1066    OrderSet[i] = Malloc<int>(FragmentsPerOrder[i], "KeySetsContainer::ParseManyBodyTermsKeySetsContainer::ParseManyBodyTerms: *OrderSet[]");
    10661067  for(int i=Order;i--;)
    10671068    FragmentsPerOrder[i] = 0;
  • src/stackclass.hpp

    r89c8b2 r29812d  
    33
    44#include "verbose.hpp"
     5#include "memoryallocator.hpp"
    56
    67template <typename T> class StackClass;
     
    4344  NextFreeField = 0;
    4445  EntryCount = dimension;
    45   StackList = (T *) Malloc(sizeof(T)*EntryCount, "StackClass::StackClass: **StackList");
     46  StackList = Malloc<T>(EntryCount, "StackClass::StackClass: **StackList");
    4647};
    4748
     
    5051template <typename T> StackClass<T>::~StackClass()
    5152{
    52   Free((void **)&StackList, "StackClass::StackClass: **StackList");
     53  Free(&StackList);
    5354};
    5455
  • src/tesselation.cpp

    r89c8b2 r29812d  
    77
    88#include "tesselation.hpp"
     9#include "memoryallocator.hpp"
    910
    1011// ======================================== Points on Boundary =================================
     
    504505TesselPoint::~TesselPoint()
    505506{
    506   Free((void **)&Name, "TesselPoint::~TesselPoint: *Name");
     507  Free(&Name);
    507508};
    508509
  • src/vector.cpp

    r89c8b2 r29812d  
    88#include "defs.hpp"
    99#include "helpers.hpp"
     10#include "memoryallocator.hpp"
    1011#include "leastsquaremin.hpp"
    1112#include "vector.hpp"
     
    674675double * Vector::InverseMatrix(double *A)
    675676{
    676   double *B = (double *) Malloc(sizeof(double)*NDIM*NDIM, "Vector::InverseMatrix: *B");
     677  double *B = Malloc<double>(NDIM * NDIM, "Vector::InverseMatrix: *B");
    677678  double detA = RDET3(A);
    678679  double detAReci;
Note: See TracChangeset for help on using the changeset viewer.