Changeset 12457


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

changing xmalloc to xNew and xfree to xDelete

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

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/objects/DakotaPlugin.cpp

    r12446 r12457  
    7474        }
    7575        /*The descriptors: */
    76         variable_descriptors=(char**)xmalloc(numACV*sizeof(char*));
     76        variable_descriptors=xNew<char*>(numACV);
    7777        for(i=0;i<numACV;i++){
    7878                string label=xCLabels[i];
    79                 variable_descriptor=(char*)xmalloc((strlen(label.c_str())+1)*sizeof(char));
     79                variable_descriptor=xNew<char>(strlen(label.c_str())+1);
    8080                memcpy(variable_descriptor,label.c_str(),(strlen(label.c_str())+1)*sizeof(char));
    8181
     
    100100        for(i=0;i<numACV;i++){
    101101                variable_descriptor=variable_descriptors[i];
    102                 xfree((void**)&variable_descriptor);
     102                xDelete<char>(variable_descriptor);
    103103        }
    104         xfree((void**)&variable_descriptors);
     104        xDelete<char*>(variable_descriptors);
    105105        xDelete<IssmDouble>(responses);
    106106
  • issm/trunk-jpl/src/c/objects/DofIndexing.cpp

    r12365 r12457  
    5151
    5252        if(this->gsize>0){
    53                 this->f_set=(bool*)xmalloc(this->gsize*sizeof(bool));
    54                 this->s_set=(bool*)xmalloc(this->gsize*sizeof(bool));
     53                this->f_set=xNew<bool>(this->gsize);
     54                this->s_set=xNew<bool>(this->gsize);
    5555                this->svalues=xNew<IssmDouble>(this->gsize);
    56                 if(in->doftype)this->doftype=(int*)xmalloc(this->gsize*sizeof(int));
    57                 this->gdoflist=(int*)xmalloc(this->gsize*sizeof(int));
     56                if(in->doftype)this->doftype=xNew<int>(this->gsize);
     57                this->gdoflist=xNew<int>(this->gsize);
    5858        }
    5959        else{
     
    6464                this->gdoflist=NULL;
    6565        }
    66         if(this->fsize>0 && this->fsize!=UNDEF)this->fdoflist=(int*)xmalloc(this->fsize*sizeof(int)); else this->fdoflist=NULL;
    67         if(this->ssize>0 && this->ssize!=UNDEF)this->sdoflist=(int*)xmalloc(this->ssize*sizeof(int)); else this->sdoflist=NULL;
     66        if(this->fsize>0 && this->fsize!=UNDEF)this->fdoflist=xNew<int>(this->fsize); else this->fdoflist=NULL;
     67        if(this->ssize>0 && this->ssize!=UNDEF)this->sdoflist=xNew<int>(this->ssize); else this->sdoflist=NULL;
    6868
    6969        if(this->gsize>0){
     
    8282DofIndexing::~DofIndexing(){ //destructor
    8383
    84         xfree((void**)&f_set);
    85         xfree((void**)&s_set);
     84        xDelete<bool>(f_set);
     85        xDelete<bool>(s_set);
    8686        xDelete<IssmDouble>(svalues);
    87         xfree((void**)&doftype);
    88         xfree((void**)&gdoflist);
    89         xfree((void**)&fdoflist);
    90         xfree((void**)&sdoflist);
     87        xDelete<int>(doftype);
     88        xDelete<int>(gdoflist);
     89        xDelete<int>(fdoflist);
     90        xDelete<int>(sdoflist);
    9191
    9292}
     
    102102        /*allocate: */
    103103        if(this->gsize>0){
    104                 this->f_set=(bool*)xmalloc(this->gsize*sizeof(bool));
    105                 this->s_set=(bool*)xmalloc(this->gsize*sizeof(bool));
     104                this->f_set=xNew<bool>(this->gsize);
     105                this->s_set=xNew<bool>(this->gsize);
    106106                this->svalues=xNew<IssmDouble>(this->gsize);
    107                 if(in_doftype)this->doftype=(int*)xmalloc(this->gsize*sizeof(int));
    108                 this->gdoflist=(int*)xmalloc(this->gsize*sizeof(int));
     107                if(in_doftype)this->doftype=xNew<int>(this->gsize);
     108                this->gdoflist=xNew<int>(this->gsize);
    109109        }
    110110
     
    131131                for(i=0;i<this->gsize;i++) if(f_set[i])size++;
    132132                this->fsize=size;
    133                 xfree((void**)&this->fdoflist);
    134                 if(this->fsize)this->fdoflist=(int*)xmalloc(size*sizeof(int));
     133                xDelete<int>(this->fdoflist);
     134                if(this->fsize)this->fdoflist=xNew<int>(size);
    135135                else this->fdoflist=NULL;
    136136        }
     
    139139                for(i=0;i<this->gsize;i++) if(s_set[i])size++;
    140140                this->ssize=size;
    141                 xfree((void**)&this->sdoflist);
    142                 if(this->ssize)this->sdoflist=(int*)xmalloc(size*sizeof(int));
     141                xDelete<int>(this->sdoflist);
     142                if(this->ssize)this->sdoflist=xNew<int>(size);
    143143                else this->sdoflist=NULL;
    144144        }
  • issm/trunk-jpl/src/c/objects/FemModel.cpp

    r12389 r12457  
    3939       
    4040        /*Dynamically allocate whatever is a list of length nummodels: */
    41         analysis_type_list=(int*)xmalloc(nummodels*sizeof(int));
     41        analysis_type_list=xNew<int>(nummodels);
    4242
    4343        /*Initialize: */
     
    8585
    8686        /*Delete all the datasets: */
    87         xfree((void**)&analysis_type_list);
     87        xDelete<int>(analysis_type_list);
    8888        delete elements;
    8989        delete nodes;
  • issm/trunk-jpl/src/c/objects/Hook.cpp

    r12365 r12457  
    4747        else{
    4848                /*Allocate: */
    49                 this->objects=(Object**)xmalloc(this->num*sizeof(Object*));
    50                 this->ids=(int*)xmalloc(this->num*sizeof(int));
    51                 this->offsets=(int*)xmalloc(this->num*sizeof(int));
     49                this->objects=xNew<Object*>(this->num);
     50                this->ids=xNew<int>(this->num);
     51                this->offsets=xNew<int>(this->num);
    5252
    5353                /*Copy ids: */
     
    6363Hook::~Hook(){
    6464        /*deallocate: */
    65         xfree((void**)&this->objects);
    66         xfree((void**)&this->ids);
    67         xfree((void**)&this->offsets);
     65        xDelete<Object*>(this->objects);
     66        xDelete<int>(this->ids);
     67        xDelete<int>(this->offsets);
    6868        return;
    6969}
     
    132132        output->num=this->num;
    133133        if(output->num){
    134                 output->objects=(Object**)xmalloc(output->num*sizeof(Object*));
    135                 output->ids=(int*)xmalloc(output->num*sizeof(int));
    136                 output->offsets=(int*)xmalloc(output->num*sizeof(int));
     134                output->objects=xNew<Object*>(output->num);
     135                output->ids=xNew<int>(output->num);
     136                output->offsets=xNew<int>(output->num);
    137137        }
    138138       
     
    252252        if(output->num<1) _error_("Trying to spawn an empty ElementProperties!");
    253253
    254         output->objects=(Object**)xmalloc(output->num*sizeof(Object*));
    255         output->ids=(int*)xmalloc(output->num*sizeof(int));
    256         output->offsets=(int*)xmalloc(output->num*sizeof(int));
     254        output->objects=xNew<Object*>(output->num);
     255        output->ids=xNew<int>(output->num);
     256        output->offsets=xNew<int>(output->num);
    257257
    258258        for(i=0;i<output->num;i++){
  • issm/trunk-jpl/src/c/objects/IoModel.cpp

    r12450 r12457  
    5353
    5454        /*Initialize data: */
    55         this->data=(IssmPDouble**)xmalloc(MaximumNumberOfEnums*sizeof(IssmPDouble*));
     55        this->data=xNew<IssmPDouble*>(MaximumNumberOfEnums);
    5656        for(int i=0;i<MaximumNumberOfEnums;i++) this->data[i]=NULL;
    5757       
     
    8484        #endif
    8585
    86         xfree((void**)&this->data);
    87         xfree((void**)&this->my_elements);
    88         xfree((void**)&this->my_nodes);
    89         xfree((void**)&this->my_vertices);
    90         xfree((void**)&this->singlenodetoelementconnectivity);
    91         xfree((void**)&this->numbernodetoelementconnectivity);
     86        xDelete<IssmPDouble*>(this->data);
     87        xDelete<bool>(this->my_elements);
     88        xDelete<bool>(this->my_nodes);
     89        xDelete<int>(this->my_vertices);
     90        xDelete<int>(this->singlenodetoelementconnectivity);
     91        xDelete<int>(this->numbernodetoelementconnectivity);
    9292}
    9393/*}}}*/
     
    305305
    306306                                                if(string_size){
    307                                                         string=(char*)xmalloc((string_size+1)*sizeof(char));
     307                                                        string=xNew<char>(string_size+1);
    308308                                                        string[string_size]='\0';
    309309
     
    315315                                                }
    316316                                                else{
    317                                                         string=(char*)xmalloc(sizeof(char));
     317                                                        string=xNew<char>(1);
    318318                                                        string[0]='\0';
    319319                                                }
     
    323323
    324324                                                /*Free string*/
    325                                                 xfree((void**)&string);
     325                                                xDelete<char>(string);
    326326
    327327                                                break;
     
    404404                                        MPI_Bcast(&string_size,1,MPI_INT,0,MPI_COMM_WORLD);
    405405                                        if(string_size){
    406                                                 string=(char*)xmalloc((string_size+1)*sizeof(char));
     406                                                string=xNew<char>((string_size+1));
    407407                                                string[string_size]='\0';
    408408
     
    411411                                        }
    412412                                        else{
    413                                                 string=(char*)xmalloc(sizeof(char));
     413                                                string=xNew<char>(1);
    414414                                                string[0]='\0';
    415415                                        }
     
    418418
    419419                                        /*Free string*/
    420                                         xfree((void**)&string);
     420                                        xDelete<char>(string);
    421421
    422422                                        break;
     
    559559        /*Now allocate string: */
    560560        if(string_size){
    561                 string=(char*)xmalloc((string_size+1)*sizeof(char));
     561                string=xNew<char>((string_size+1));
    562562                string[string_size]='\0';
    563563
     
    571571        }
    572572        else{
    573                 string=(char*)xmalloc(sizeof(char));
     573                string=xNew<char>(1);
    574574                string[0]='\0';
    575575        }
     
    621621        /*Now allocate matrix: */
    622622        if(M*N){
    623                 matrix=(IssmPDouble*)xmalloc(M*N*sizeof(IssmPDouble));
     623                matrix=xNew<IssmPDouble>(M*N);
    624624
    625625                /*Read matrix on node 0, then broadcast: */
     
    635635        /*Now cast to integer: */
    636636        if(M*N){
    637                 integer_matrix=(int*)xmalloc(M*N*sizeof(int));
     637                integer_matrix=xNew<int>(M*N);
    638638                for (i=0;i<M;i++){
    639639                        for (j=0;j<N;j++){
     
    646646        }
    647647        /*Free ressources:*/
    648         xfree((void**)&matrix);
     648        xDelete<IssmPDouble>(matrix);
    649649
    650650        /*Assign output pointers: */
     
    740740        /*Now allocate string array: */
    741741        if(numstrings){
    742                 strings=(char**)xmalloc(numstrings*sizeof(char*));
     742                strings=xNew<char*>(numstrings);
    743743                for(i=0;i<numstrings;i++)strings[i]=NULL;
    744744
     
    753753                        #endif
    754754                        if(string_size){
    755                                 string=(char*)xmalloc((string_size+1)*sizeof(char));
     755                                string=xNew<char>((string_size+1));
    756756                                string[string_size]='\0';
    757757
     
    765765                        }
    766766                        else{
    767                                 string=(char*)xmalloc(sizeof(char));
     767                                string=xNew<char>(1);
    768768                                string[0]='\0';
    769769                        }
     
    812812
    813813                /*Allocate matrices :*/
    814                 matrices=(IssmPDouble**)xmalloc(numrecords*sizeof(IssmPDouble*));
    815                 mdims=(int*)xmalloc(numrecords*sizeof(int));
    816                 ndims=(int*)xmalloc(numrecords*sizeof(int));
     814                matrices=xNew<IssmPDouble*>(numrecords);
     815                mdims=xNew<int>(numrecords);
     816                ndims=xNew<int>(numrecords);
    817817
    818818                for(i=0;i<numrecords;i++){
     
    841841                        /*Now allocate matrix: */
    842842                        if(M*N){
    843                                 matrix=(IssmPDouble*)xmalloc(M*N*sizeof(IssmPDouble));
     843                                matrix=xNew<IssmPDouble>(M*N);
    844844
    845845                                /*Read matrix on node 0, then broadcast: */
     
    886886                case 3: {//IssmPDouble
    887887                          IssmPDouble *value = NULL;
    888                           value=(IssmPDouble*)xmalloc(1*sizeof(IssmPDouble));
     888                          value=xNew<IssmPDouble>(1);
    889889                          FetchData(value,index+1);
    890890                          option = new OptionDouble();
     
    11421142        }
    11431143        /*Free ressources:*/
    1144         xfree((void**)&IssmPDoublevector);
    1145         xfree((void**)&string);
     1144        xDelete<IssmPDouble>(IssmPDoublevector);
     1145        xDelete<char>(string);
    11461146}
    11471147/*FUNCTION IoModel::LastIndex{{{*/
  • issm/trunk-jpl/src/c/objects/Node.cpp

    r12365 r12457  
    801801        if(setenum==FsetEnum){
    802802                if(this->indexing.fsize){
    803                         indices=(int*)xmalloc(this->indexing.fsize*sizeof(int));
     803                        indices=xNew<int>(this->indexing.fsize);
    804804                        values=xNew<IssmDouble>(this->indexing.fsize);
    805805
     
    819819        else if(setenum==SsetEnum){
    820820                if(this->indexing.ssize){
    821                         indices=(int*)xmalloc(this->indexing.ssize*sizeof(int));
     821                        indices=xNew<int>(this->indexing.ssize);
    822822                        values=xNew<IssmDouble>(this->indexing.ssize);
    823823
     
    839839        /*Free ressources:*/
    840840        xDelete<IssmDouble>(values);
    841         xfree((void**)&indices);
     841        xDelete<int>(indices);
    842842}
    843843/*}}}*/
Note: See TracChangeset for help on using the changeset viewer.