Changeset 13038


Ignore:
Timestamp:
08/14/12 17:12:51 (13 years ago)
Author:
Mathieu Morlighem
Message:

CHG: getting rid of xmalloc

Location:
issm/trunk-jpl/src/modules
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/modules/Chaco/Chaco.cpp

    r13036 r13038  
    5454        nvtxs = mxGetN(A_IN);
    5555        mwstart = mxGetJc(A_IN);
    56         start=(int*)xmalloc((nvtxs+1)*sizeof(int));
     56        start=xNew<int>((nvtxs+1));
    5757        for (i=0; i<nvtxs+1;i++)start[i]=(int)mwstart[i];
    5858
    5959        mwadjacency = mxGetIr(A_IN);
    60         adjacency = (int*)xmalloc(mxGetNzmax(A_IN)*sizeof(int));
     60        adjacency = xNew<int>(mxGetNzmax(A_IN));
    6161        for (i=0; i<mxGetNzmax(A_IN); i++) adjacency[i]= (int)mwadjacency[i];
    6262
    6363        nedges = start[nvtxs];
    6464        if(!mxIsEmpty(EWGTS_IN)){
    65                 ewgts = (float*)xcalloc(nedges, sizeof(float));
     65                ewgts = xNewZeroInit<float>(nedges);
    6666                doublepointer=mxGetPr(A_IN);
    6767                for (i = 0; i < nedges; i++)ewgts[i] = (float)doublepointer[i];
     
    7777        for (i=0;i<(nterms<10?nterms:10);i++) options[i]=in_options[i]; //copy in_options into default options
    7878        FetchData(&npart,NPARTS_IN);
    79         nparts=(int*)xmalloc(sizeof(int)); nparts[0]=npart; //weird Chacox interface ain't it?
     79        nparts=xNew<int>(1); nparts[0]=npart; //weird Chacox interface ain't it?
    8080        FetchData(&goal,&nterms,GOAL_IN);
    8181       
     
    104104       
    105105        /*Allocate output: */
    106         assignment = (short*)xcalloc(nvtxs, sizeof(short));
     106        assignment = xNewZeroInit<short>(nvtxs);
    107107       
    108108    /*Call core: */
     
    110110
    111111    /*Output data: */
    112         doubleassignment=(double*)xmalloc(nvtxs*sizeof(double));
     112        doubleassignment=xNew<double>(nvtxs);
    113113        for(i=0;i<nvtxs;i++) doubleassignment[i]=(double)assignment[i];
    114114        WriteData(ASSGN_OUT,doubleassignment,nvtxs);
  • issm/trunk-jpl/src/modules/ContourToNodes/ContourToNodes.cpp

    r12517 r13038  
    6868
    6969        numcontours=mxGetNumberOfElements(matlabstructure);
    70         contours=(Contour**)xmalloc(numcontours*sizeof(Contour*));
     70        contours=xNew<Contour*>(numcontours);
    7171        for(i=0;i<numcontours;i++){
    7272                //allocate
    73                 contouri=(Contour*)xmalloc(sizeof(Contour));
     73                contouri=xNew<Contour>(1);
    7474                //retrieve dimension of this contour.
    7575                contouri->nods=(int)mxGetScalar(mxGetField(matlabstructure,i,"nods"));
  • issm/trunk-jpl/src/modules/InternalFront/InternalFront.cpp

    r13036 r13038  
    3636        /*Allocate and initialize all variables*/
    3737        numberofsegments=0;
    38         front=(int*)xmalloc(3*numberofelements*4*sizeof(int));
     38        front=xNew<int>(3*numberofelements*4);
    3939
    4040        /*Loop over all elements on water*/
     
    8181        /*Now that we know how many segments there is we can allocate the final matrix*/
    8282        if(numberofsegments){
    83                 front2=(double*)xmalloc(4*numberofsegments*sizeof(double));
     83                front2=xNew<double>(4*numberofsegments);
    8484                for(i=0;i<4*numberofsegments;i++) front2[i]=(double)front[i];
    8585        }
  • issm/trunk-jpl/src/modules/InterpFromMesh2d/InterpFromMesh2d.cpp

    r13036 r13038  
    100100                /*contours: */
    101101                numcontours=mxGetNumberOfElements(matlabstructure);
    102                 contours=(Contour**)xmalloc(numcontours*sizeof(Contour*));
     102                contours=xNew<Contour*>(numcontours);
    103103                for(i=0;i<numcontours;i++){
    104104                        //allocate
    105                         contouri=(Contour*)xmalloc(sizeof(Contour));
     105                        contouri=xNew<Contour>(1);
    106106                        //retrieve dimension of this contour.
    107107                        contouri->nods=(int)mxGetScalar(mxGetField(matlabstructure,i,"nods"));
  • issm/trunk-jpl/src/modules/KMLMeshWrite/KMLMeshWrite.cpp

    r13036 r13038  
    5555                        if (notesi && mxIsChar(notesi) && mxGetNumberOfElements(notesi)) {
    5656                                if (!notes) {
    57                                         notes=(char *) xmalloc((mxGetNumberOfElements(notesi)+1)*sizeof(char));
     57                                        notes=xNew<char>(mxGetNumberOfElements(notesi)+1);
    5858                                        mxGetString(notesi,notes,mxGetNumberOfElements(notesi)+1);
    5959                                }
  • issm/trunk-jpl/src/modules/MeshPartition/MeshPartition.cpp

    r12517 r13038  
    7474
    7575        /*Post process node_partitioning and element_partitioning to be in double format. Metis needed them in int* format: */
    76         element_partitioning=(double*)xmalloc(numberofelements*sizeof(double));
     76        element_partitioning=xNew<double>(numberofelements);
    7777        for (i=0;i<numberofelements;i++){
    7878                element_partitioning[i]=(double)int_element_partitioning[i]+1; //Metis indexing from 0, matlab from 1.
    7979        }
    8080       
    81         node_partitioning=(double*)xmalloc(numberofvertices*sizeof(double));
     81        node_partitioning=xNew<double>(numberofvertices);
    8282        for (i=0;i<numberofvertices;i++){
    8383                node_partitioning[i]=(double)int_node_partitioning[i]+1; //Metis indexing from 0, matlab from 1.
  • issm/trunk-jpl/src/modules/MeshProfileIntersection/MeshProfileIntersection.cpp

    r13036 r13038  
    5555        FetchData(&double_index,&nel,&dummy,INDEX);
    5656        if(dummy!=3 && dummy!=6)_error_("element triangulation should be of 3 or 6 column width!");
    57         index=(int*)xmalloc(nel*3*sizeof(int));
     57        index=xNew<int>(nel*3);
    5858        for(i=0;i<nel;i++){
    5959                for(j=0;j<3;j++){
     
    6767        //contours
    6868        numcontours=mxGetNumberOfElements(matlabstructure);
    69         contours=(Contour**)xmalloc(numcontours*sizeof(Contour*));
     69        contours=xNew<Contour*>(numcontours);
    7070        for(i=0;i<numcontours;i++){
    7171                //allocate
    72                 contouri=(Contour*)xmalloc(sizeof(Contour));
     72                contouri=xNew<Contour>(1);
    7373                //retrieve dimension of this contour.
    7474                contouri->nods=(int)mxGetScalar(mxGetField(matlabstructure,i,"nods"));
  • issm/trunk-jpl/src/modules/TriMeshProcessRifts/TriMeshProcessRifts.cpp

    r13036 r13038  
    7373                nel=mxGetM(prhs[0]);
    7474                tindex_in=mxGetPr(prhs[0]);
    75                 index_in=(double*)xmalloc(nel*3*sizeof(double));
     75                index_in=xNew<double>(nel*3);
    7676                for (i=0;i<nel;i++){
    7777                        for (j=0;j<3;j++){
     
    8888                nods=mxGetM(prhs[1]);
    8989                x_inm=mxGetPr(prhs[1]);
    90                 x_in=(double*)xmalloc(nods*sizeof(double));
     90                x_in=xNew<double>(nods);
    9191                for (i=0;i<nods;i++){
    9292                        x_in[i]=x_inm[i];
     
    100100        if(mxIsDouble(prhs[2])){
    101101                y_inm=mxGetPr(prhs[2]);
    102                 y_in=(double*)xmalloc(nods*sizeof(double));
     102                y_in=xNew<double>(nods);
    103103                for (i=0;i<nods;i++){
    104104                        y_in[i]=y_inm[i];
     
    113113                num_seg=mxGetM(prhs[3]);
    114114                tsegments_in=mxGetPr(prhs[3]);
    115                 segments_in=(double*)xmalloc(num_seg*3*sizeof(double));
     115                segments_in=xNew<double>(num_seg*3);
    116116                for (i=0;i<num_seg;i++){
    117117                        for (j=0;j<3;j++){
     
    127127        if(mxIsDouble(prhs[4])){
    128128                tsegmentmarkers_in=mxGetPr(prhs[4]);
    129                 segmentmarkers_in=(double*)xmalloc(num_seg*sizeof(double));
     129                segmentmarkers_in=xNew<double>(num_seg);
    130130                for (i=0;i<num_seg;i++){
    131131                        segmentmarkers_in[i]=tsegmentmarkers_in[i];
Note: See TracChangeset for help on using the changeset viewer.