Changeset 12459


Ignore:
Timestamp:
06/18/12 16:33:01 (13 years ago)
Author:
Mathieu Morlighem
Message:

changing xmalloc to xNew and xfree to xDelete

Location:
issm/trunk-jpl/src/c/Container
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified issm/trunk-jpl/src/c/Container/DataSet.cpp

    r12365 r12459  
    5959        copy->presorted=presorted;
    6060        if(sorted_ids){
    61                 copy->sorted_ids=(int*)xmalloc(objects.size()*sizeof(int));
     61                copy->sorted_ids=xNew<int>(objects.size());
    6262                memcpy(copy->sorted_ids,sorted_ids,objects.size()*sizeof(int));
    6363        }
    6464        if(id_offsets){
    65                 copy->id_offsets=(int*)xmalloc(objects.size()*sizeof(int));
     65                copy->id_offsets=xNew<int>(objects.size());
    6666                memcpy(copy->id_offsets,id_offsets,objects.size()*sizeof(int));
    6767        }
     
    8080DataSet::~DataSet(){
    8181        clear();
    82         xfree((void**)&sorted_ids);
    83         xfree((void**)&id_offsets);
     82        xDelete<int>(sorted_ids);
     83        xDelete<int>(id_offsets);
    8484}
    8585/*}}}*/
     
    221221
    222222                /*Delete existing ids*/
    223                 xfree((void**)&sorted_ids);
    224                 xfree((void**)&id_offsets);
     223                xDelete<int>(sorted_ids);
     224                xDelete<int>(id_offsets);
    225225
    226226                /*Allocate new ids*/
    227                 sorted_ids=(int*)xmalloc(objects.size()*sizeof(int));
    228                 id_offsets=(int*)xmalloc(objects.size()*sizeof(int));
     227                sorted_ids=xNew<int>(objects.size());
     228                id_offsets=xNew<int>(objects.size());
    229229
    230230                /*Build id_offsets and sorted_ids*/
  • TabularUnified issm/trunk-jpl/src/c/Container/Elements.cpp

    r12365 r12459  
    215215                #ifdef _HAVE_MPI_
    216216                if(my_rank!=minrank){
    217                         resultsenums=(int*)xmalloc(numberofresults*sizeof(int));
    218                         resultssizes=(int*)xmalloc(numberofresults*sizeof(int));
    219                         resultstimes=(double*)xmalloc(numberofresults*sizeof(double));
    220                         resultssteps=(int*)xmalloc(numberofresults*sizeof(int));
     217                        resultsenums=xNew<int>(numberofresults);
     218                        resultssizes=xNew<int>(numberofresults);
     219                        resultstimes=xNew<double>(numberofresults);
     220                        resultssteps=xNew<int>(numberofresults);
    221221                }
    222222                MPI_Bcast(resultsenums,numberofresults,MPI_INT,minrank,MPI_COMM_WORLD);
     
    250250                        /*clean up*/
    251251                        xdelete(&vector);
    252                         xfree((void**)&vector_serial);
     252                        xDelete<double>(vector_serial);
    253253                }
    254254        }
     
    269269
    270270        /*Free ressources:*/
    271         xfree((void**)&resultsenums);
    272         xfree((void**)&resultssizes);
    273         xfree((void**)&resultstimes);
    274         xfree((void**)&resultssteps);
     271        xDelete<int>(resultsenums);
     272        xDelete<int>(resultssizes);
     273        xDelete<int>(resultssteps);
     274        xDelete<double>(resultstimes);
    275275        delete patch;
    276276}
  • TabularUnified issm/trunk-jpl/src/c/Container/Nodes.cpp

    r12365 r12459  
    8484         * cpus by the total last dofs of the previus cpu, starting from 0.
    8585         * First: get number of dofs for each cpu*/
    86         alldofcount=(int*)xmalloc(num_procs*sizeof(int));
     86        alldofcount=xNew<int>(num_procs);
    8787        #ifdef _HAVE_MPI_
    8888        MPI_Gather(&dofcount,1,MPI_INT,alldofcount,1,MPI_INT,0,MPI_COMM_WORLD);
     
    113113        numnodes=this->NumberOfNodes(analysis_type);
    114114        if(numnodes*maxdofspernode){
    115                 truedofs=   (int*)xcalloc(numnodes*maxdofspernode,sizeof(int)); //initialize to 0, so that we can pick up the max
    116                 alltruedofs=(int*)xcalloc(numnodes*maxdofspernode,sizeof(int));
     115                truedofs=   xNewZeroInit<int>(numnodes*maxdofspernode); //initialize to 0, so that we can pick up the max
     116                alltruedofs=xNewZeroInit<int>(numnodes*maxdofspernode);
    117117        }
    118118
     
    139139
    140140        /* Free ressources: */
    141         xfree((void**)&alldofcount);
    142         xfree((void**)&truedofs);
    143         xfree((void**)&alltruedofs);
     141        xDelete<int>(alldofcount);
     142        xDelete<int>(truedofs);
     143        xDelete<int>(alltruedofs);
    144144}
    145145/*}}}*/
     
    158158
    159159        /*Allocate ranks: */
    160         ranks=(int*)xmalloc(numnodes*sizeof(int));
    161         minranks=(int*)xmalloc(numnodes*sizeof(int));
     160        ranks=xNew<int>(numnodes);
     161        minranks=xNew<int>(numnodes);
    162162
    163163        for(i=0;i<numnodes;i++)ranks[i]=num_procs; //no cpu can have rank num_procs. This is the maximum limit.
     
    190190
    191191        /*Free ressources: */
    192         xfree((void**)&ranks);
    193         xfree((void**)&minranks);
     192        xDelete<int>(ranks);
     193        xDelete<int>(minranks);
    194194
    195195}
  • TabularUnified issm/trunk-jpl/src/c/Container/Observations.cpp

    r12422 r12459  
    162162                *pobs=observation->value;
    163163        }
    164         xfree((void**)&indices);
     164        xDelete<int>(indices);
    165165
    166166}/*}}}*/
     
    189189        this->quadtree->RangeSearch(&tempindices,&tempnobs,x_interp,y_interp,radius);
    190190        if(tempnobs){
    191                 indices = (int*)xmalloc(tempnobs*sizeof(int));
    192                 dists   = (double*)xmalloc(tempnobs*sizeof(double));
     191                indices = xNew<int>(tempnobs);
     192                dists   = xNew<double>(tempnobs);
    193193        }
    194194        nobs = 0;
     
    225225                }
    226226        } 
    227         xfree((void**)&dists);
    228         xfree((void**)&tempindices);
     227        xDelete<double>(dists);
     228        xDelete<int>(tempindices);
    229229
    230230        if(nobs){
    231231                /*Allocate vectors*/
    232                 x   = (double*)xmalloc(nobs*sizeof(double));
    233                 y   = (double*)xmalloc(nobs*sizeof(double));
    234                 obs = (double*)xmalloc(nobs*sizeof(double));
     232                x   = xNew<double>(nobs);
     233                y   = xNew<double>(nobs);
     234                obs = xNew<double>(nobs);
    235235
    236236                /*Loop over all observations and fill in x, y and obs*/
     
    242242
    243243        /*Assign output pointer*/
    244         xfree((void**)&indices);
     244        xDelete<int>(indices);
    245245        *px=x;
    246246        *py=y;
     
    261261
    262262        if(nobs){
    263                 x   = (double*)xmalloc(nobs*sizeof(double));
    264                 y   = (double*)xmalloc(nobs*sizeof(double));
    265                 obs = (double*)xmalloc(nobs*sizeof(double));
     263                x   = xNew<double>(nobs);
     264                y   = xNew<double>(nobs);
     265                obs = xNew<double>(nobs);
    266266                for(int i=0;i<this->Size();i++){
    267267                        observation=(Observation*)this->GetObjectByOffset(i);
     
    321321        /*clean-up*/
    322322        *pprediction = prediction;
    323         xfree((void**)&x);
    324         xfree((void**)&y);
    325         xfree((void**)&obs);
     323        xDelete<double>(x);
     324        xDelete<double>(y);
     325        xDelete<double>(obs);
    326326}/*}}}*/
    327327/*FUNCTION Observations::InterpolationKriging{{{*/
     
    360360
    361361        /*Allocate intermediary matrix and vectors*/
    362         Gamma  = (double*)xmalloc(n_obs*n_obs*sizeof(double));
    363         gamma0 = (double*)xmalloc(n_obs*sizeof(double));
    364         ones   = (double*)xmalloc(n_obs*sizeof(double));
     362        Gamma  = xNew<double>(n_obs*n_obs);
     363        gamma0 = xNew<double>(n_obs);
     364        ones   = xNew<double>(n_obs);
    365365
    366366        /*First: Create semivariogram matrix for observations*/
     
    401401        *pprediction = prediction;
    402402        *perror = error;
    403         xfree((void**)&x);
    404         xfree((void**)&y);
    405         xfree((void**)&obs);
    406         xfree((void**)&Gamma);
    407         xfree((void**)&gamma0);
    408         xfree((void**)&ones);
    409         xfree((void**)&GinvG0);
    410         xfree((void**)&Ginv1);
    411         xfree((void**)&GinvZ);
     403        xDelete<double>(x);
     404        xDelete<double>(y);
     405        xDelete<double>(obs);
     406        xDelete<double>(Gamma);
     407        xDelete<double>(gamma0);
     408        xDelete<double>(ones);
     409        xDelete<double>(GinvG0);
     410        xDelete<double>(Ginv1);
     411        xDelete<double>(GinvZ);
    412412
    413413}/*}}}*/
     
    445445        Observation *observation2 = NULL;
    446446
    447         double *counter = (double*)xmalloc(n*sizeof(double));
     447        double *counter = xNew<double>(n);
    448448        for(j=0;j<n;j++) counter[j] = 0.0;
    449449        for(j=0;j<n;j++) gamma[j]   = 0.0;
     
    474474
    475475        /*Assign output pointer*/
    476         xfree((void**)&counter);
    477 }/*}}}*/
     476        xDelete<double>(counter);
     477}/*}}}*/
  • TabularUnified issm/trunk-jpl/src/c/Container/Options.cpp

    r12365 r12459  
    222222        else{
    223223                stringsize=strlen(default_value)+1;
    224                 outstring=(char*)xmalloc(stringsize*sizeof(char));
     224                outstring=xNew<char>(stringsize);
    225225                memcpy(outstring,default_value,stringsize*sizeof(char));
    226226                *pvalue=outstring;
     
    246246                if(option->ObjectEnum()==OptionCellEnum){
    247247                        if (option->NumEl()) {
    248                                 *ppvalue=(char **) xmalloc(option->NumEl()*sizeof(char *));
     248                                *ppvalue=xNew<char*>(option->NumEl());
    249249                                if (numel) *numel=option->NumEl();
    250250                                option->Get(&options);
  • TabularUnified issm/trunk-jpl/src/c/Container/Vertices.cpp

    r12365 r12459  
    6060         * cpus by the total last dofs of the previus cpu, starting from 0.
    6161         * First: bet number of dofs for each cpu*/
    62         alldofcount=(int*)xmalloc(num_procs*sizeof(int));
     62        alldofcount=xNew<int>(num_procs);
    6363        #ifdef _HAVE_MPI_
    6464        MPI_Gather(&dofcount,1,MPI_INT,alldofcount,1,MPI_INT,0,MPI_COMM_WORLD);
     
    8383         * object that is not a clone, tell them to show their dofs, so that later on, they can get picked
    8484         * up by their clones: */
    85         truedofs   =(int*)xcalloc(numberofobjects*numberofdofsperobject,sizeof(int));
    86         alltruedofs=(int*)xcalloc(numberofobjects*numberofdofsperobject,sizeof(int));
     85        truedofs   =xNewZeroInit<int>(numberofobjects*numberofdofsperobject);
     86        alltruedofs=xNewZeroInit<int>(numberofobjects*numberofdofsperobject);
    8787        for (i=0;i<this->Size();i++){
    8888                Vertex* vertex=(Vertex*)this->GetObjectByOffset(i);
     
    102102
    103103        /* Free ressources: */
    104         xfree((void**)&alldofcount);
    105         xfree((void**)&truedofs);
    106         xfree((void**)&alltruedofs);
     104        xDelete<int>(alldofcount);
     105        xDelete<int>(truedofs);
     106        xDelete<int>(alltruedofs);
    107107}
    108108/*}}}*/
     
    117117
    118118        /*Allocate ranks: */
    119         ranks=(int*)xmalloc(numberofobjects*sizeof(int));
    120         minranks=(int*)xmalloc(numberofobjects*sizeof(int));
     119        ranks=xNew<int>(numberofobjects);
     120        minranks=xNew<int>(numberofobjects);
    121121
    122122        for(i=0;i<numberofobjects;i++)ranks[i]=num_procs; //no cpu can have rank num_procs. This is the maximum limit.
     
    143143
    144144        /*Free ressources: */
    145         xfree((void**)&ranks);
    146         xfree((void**)&minranks);
     145        xDelete<int>(ranks);
     146        xDelete<int>(minranks);
    147147
    148148}
Note: See TracChangeset for help on using the changeset viewer.