Changeset 12050


Ignore:
Timestamp:
04/18/12 15:17:58 (13 years ago)
Author:
Mathieu Morlighem
Message:

ALWAYS use Matlab's memory manager in mex modules

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

Legend:

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

    r11933 r12050  
    5858
    5959        mwstart = mxGetJc(A_IN);
    60         start=(int*)xmalloc(nvtxs*sizeof(int));
     60        start=(int*)mxMalloc(nvtxs*sizeof(int));
    6161        for (i=0; i<nvtxs+1;i++)start[i]=(int)mwstart[i];
    6262
    6363        mwadjacency = mxGetIr(A_IN);
    64         adjacency = (int*)xmalloc(mxGetNzmax(A_IN)*sizeof(int));
     64        adjacency = (int*)mxMalloc(mxGetNzmax(A_IN)*sizeof(int));
    6565        for (i=0; i<mxGetNzmax(A_IN); i++) adjacency[i]= (int)mwadjacency[i];
    6666
    6767        nedges = start[nvtxs];
    6868        if(!mxIsEmpty(EWGTS_IN)){
    69                 ewgts = (float *) xcalloc(nedges, sizeof(float));
     69                ewgts = (float *) mxCalloc(nedges, sizeof(float));
    7070                doublepointer=mxGetPr(A_IN);
    7171                for (i = 0; i < nedges; i++)ewgts[i] = (float)doublepointer[i];
     
    8484       
    8585        FetchData(&npart,NPARTS_IN);
    86         nparts=(int*)xmalloc(sizeof(int)); nparts[0]=npart; //weird Chacox interface ain't it?
     86        nparts=(int*)mxMalloc(sizeof(int)); nparts[0]=npart; //weird Chacox interface ain't it?
    8787
    8888        FetchData(&goal,&nterms,GOAL_IN);
     
    112112       
    113113        /*Allocate output: */
    114         assignment = (short *) xcalloc(nvtxs, sizeof(short));
     114        assignment = (short *) mxCalloc(nvtxs, sizeof(short));
    115115       
    116116    /*Call core: */
     
    118118
    119119    /*Output data: */
    120         doubleassignment=(double*)xmalloc(nvtxs*sizeof(double));
     120        doubleassignment=(double*)mxMalloc(nvtxs*sizeof(double));
    121121        for (i=0;i<nvtxs;i++) doubleassignment[i]=(double)assignment[i];
    122122        WriteData(ASSGN_OUT,doubleassignment,nvtxs);
  • issm/trunk-jpl/src/modules/ContourToMesh/ContourToMesh.cpp

    r11933 r12050  
    6565        //Fetch contours
    6666        numcontours=mxGetNumberOfElements(matlabstructure);
    67         contours=(Contour**)xmalloc(numcontours*sizeof(Contour*));
     67        contours=(Contour**)mxMalloc(numcontours*sizeof(Contour*));
    6868        for(i=0;i<numcontours;i++){
    6969                //allocate
    70                 contouri=(Contour*)xmalloc(sizeof(Contour));
     70                contouri=(Contour*)mxMalloc(sizeof(Contour));
    7171                //retrieve dimension of this contour.
    7272                contouri->nods=(int)mxGetScalar(mxGetField(matlabstructure,i,"nods"));
  • issm/trunk-jpl/src/modules/ContourToNodes/ContourToNodes.cpp

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

    r11933 r12050  
    3636        /*Allocate and initialize all variables*/
    3737        numberofsegments=0;
    38         front=(int*)xmalloc(3*numberofelements*4*sizeof(int));
     38        front=(int*)mxMalloc(3*numberofelements*4*sizeof(int));
    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=(double*)mxMalloc(4*numberofsegments*sizeof(double));
    8484                for(i=0;i<4*numberofsegments;i++) front2[i]=(double)front[i];
    8585        }
  • issm/trunk-jpl/src/modules/InterpFromMesh2d/InterpFromMesh2d.cpp

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

    r11933 r12050  
    7878                /*contours: */
    7979                numcontours=mxGetNumberOfElements(matlabstructure);
    80                 contours=(Contour**)xmalloc(numcontours*sizeof(Contour*));
     80                contours=(Contour**)mxMalloc(numcontours*sizeof(Contour*));
    8181                for(i=0;i<numcontours;i++){
    8282                        //allocate
    83                         contouri=(Contour*)xmalloc(sizeof(Contour));
     83                        contouri=(Contour*)mxMalloc(sizeof(Contour));
    8484                        //retrieve dimension of this contour.
    8585                        contouri->nods=(int)mxGetScalar(mxGetField(matlabstructure,i,"nods"));
  • issm/trunk-jpl/src/modules/KMLMeshWrite/KMLMeshWrite.cpp

    r12049 r12050  
    5555                        if (notesi && mxIsChar(notesi) && mxGetNumberOfElements(notesi)) {
    5656                                if (!notes) {
    57                                         notes=(char *) xmalloc((mxGetNumberOfElements(notesi)+1)*sizeof(char));
     57                                        notes=(char *) mxMalloc((mxGetNumberOfElements(notesi)+1)*sizeof(char));
    5858                                        mxGetString(notesi,notes,mxGetNumberOfElements(notesi)+1);
    5959                                }
    6060                                else {
    6161/*  note that strlen does not include trailing null  */
    62                                         notes=(char *) xrealloc(notes,(strlen(notes)+1+mxGetNumberOfElements(notesi)+1)*sizeof(char));
     62                                        notes=(char *) mxRealloc(notes,(strlen(notes)+1+mxGetNumberOfElements(notesi)+1)*sizeof(char));
    6363                                        strcat(notes,"\n");
    6464                                        mxGetString(notesi,&notes[strlen(notes)],mxGetNumberOfElements(notesi)+1);
  • issm/trunk-jpl/src/modules/MeshPartition/MeshPartition.cpp

    r11933 r12050  
    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=(double*)mxMalloc(numberofelements*sizeof(double));
    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=(double*)mxMalloc(numberofvertices*sizeof(double));
    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

    r11933 r12050  
    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=(int*)mxMalloc(nel*3*sizeof(int));
    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=(Contour**)mxMalloc(numcontours*sizeof(Contour*));
    7070        for(i=0;i<numcontours;i++){
    7171                //allocate
    72                 contouri=(Contour*)xmalloc(sizeof(Contour));
     72                contouri=(Contour*)mxMalloc(sizeof(Contour));
    7373                //retrieve dimension of this contour.
    7474                contouri->nods=(int)mxGetScalar(mxGetField(matlabstructure,i,"nods"));
  • issm/trunk-jpl/src/modules/TriMeshProcessRifts/TriMeshProcessRifts.cpp

    r8963 r12050  
    7474                nel=mxGetM(prhs[0]);
    7575                tindex_in=mxGetPr(prhs[0]);
    76                 index_in=(double*)xmalloc(nel*3*sizeof(double));
     76                index_in=(double*)mxMalloc(nel*3*sizeof(double));
    7777                for (i=0;i<nel;i++){
    7878                        for (j=0;j<3;j++){
     
    9090                nods=mxGetM(prhs[1]);
    9191                x_inm=mxGetPr(prhs[1]);
    92                 x_in=(double*)xmalloc(nods*sizeof(double));
     92                x_in=(double*)mxMalloc(nods*sizeof(double));
    9393                for (i=0;i<nods;i++){
    9494                        x_in[i]=x_inm[i];
     
    103103        if(mxIsDouble(prhs[2])){
    104104                y_inm=mxGetPr(prhs[2]);
    105                 y_in=(double*)xmalloc(nods*sizeof(double));
     105                y_in=(double*)mxMalloc(nods*sizeof(double));
    106106                for (i=0;i<nods;i++){
    107107                        y_in[i]=y_inm[i];
     
    117117                num_seg=mxGetM(prhs[3]);
    118118                tsegments_in=mxGetPr(prhs[3]);
    119                 segments_in=(double*)xmalloc(num_seg*3*sizeof(double));
     119                segments_in=(double*)mxMalloc(num_seg*3*sizeof(double));
    120120                for (i=0;i<num_seg;i++){
    121121                        for (j=0;j<3;j++){
     
    132132        if(mxIsDouble(prhs[4])){
    133133                tsegmentmarkers_in=mxGetPr(prhs[4]);
    134                 segmentmarkers_in=(double*)xmalloc(num_seg*sizeof(double));
     134                segmentmarkers_in=(double*)mxMalloc(num_seg*sizeof(double));
    135135                for (i=0;i<num_seg;i++){
    136136                        segmentmarkers_in[i]=tsegmentmarkers_in[i];
     
    270270                        pmxa_array2= mxCreateDoubleMatrix(0,0,mxREAL);
    271271                        mxSetM(pmxa_array2,1);
    272                         pair=(double*)xmalloc(2*sizeof(double));
     272                        pair=(double*)mxMalloc(2*sizeof(double));
    273273                        pair[0]=*(out_riftstips+2*i+0);
    274274                        pair[1]=*(out_riftstips+2*i+1);
     
    293293
    294294                        /*State: */
    295                         state=(double*)xmalloc(out_riftsnumpenaltypairs[i]*sizeof(double));
     295                        state=(double*)mxMalloc(out_riftsnumpenaltypairs[i]*sizeof(double));
    296296                        for(j=0;j<out_riftsnumpenaltypairs[i];j++)state[j]=FreeEnum;
    297297                        pmxa_array2= mxCreateDoubleMatrix(0,0,mxREAL);
     
    306306        else{
    307307                /*output NaN :*/
    308                 pNaN=(double*)xmalloc(sizeof(double));
     308                pNaN=(double*)mxMalloc(sizeof(double));
    309309                *pNaN=NAN;
    310310                pmxa_array= mxCreateDoubleMatrix(0,0,mxREAL);
  • issm/trunk-jpl/src/modules/TriMeshRefine/TriMeshRefine.cpp

    r4526 r12050  
    6565                nel=mxGetM(prhs[0]);
    6666                tindex_in=mxGetPr(prhs[0]);
    67                 index_in=(double*)xmalloc(nel*3*sizeof(double));
     67                index_in=(double*)mxMalloc(nel*3*sizeof(double));
    6868                for (i=0;i<nel;i++){
    6969                        for (j=0;j<3;j++){
     
    8181                nods=mxGetM(prhs[1]);
    8282                x_inm=mxGetPr(prhs[1]);
    83                 x_in=(double*)xmalloc(nods*sizeof(double));
     83                x_in=(double*)mxMalloc(nods*sizeof(double));
    8484                for (i=0;i<nods;i++){
    8585                        x_in[i]=x_inm[i];
     
    9494        if(mxIsDouble(prhs[2])){
    9595                y_inm=mxGetPr(prhs[2]);
    96                 y_in=(double*)xmalloc(nods*sizeof(double));
     96                y_in=(double*)mxMalloc(nods*sizeof(double));
    9797                for (i=0;i<nods;i++){
    9898                        y_in[i]=y_inm[i];
     
    108108                num_seg=mxGetM(prhs[3]);
    109109                tsegments_in=mxGetPr(prhs[3]);
    110                 segments_in=(double*)xmalloc(num_seg*3*sizeof(double));
     110                segments_in=(double*)mxMalloc(num_seg*3*sizeof(double));
    111111                for (i=0;i<num_seg;i++){
    112112                        for (j=0;j<3;j++){
     
    123123        if(mxIsDouble(prhs[4])){
    124124                tsegmentmarkers_in=mxGetPr(prhs[4]);
    125                 segmentmarkers_in=(double*)xmalloc(num_seg*sizeof(double));
     125                segmentmarkers_in=(double*)mxMalloc(num_seg*sizeof(double));
    126126                for (i=0;i<num_seg;i++){
    127127                        segmentmarkers_in[i]=tsegmentmarkers_in[i];
     
    152152                        mexErrMsgTxt(" ");
    153153                }
    154                 order = (char *) xmalloc((mxGetN(prhs[6])+1)*sizeof(char));
     154                order = (char *) mxMalloc((mxGetN(prhs[6])+1)*sizeof(char));
    155155                mxGetString(prhs[6],order,mxGetN(prhs[6])+1);
    156156        }
     
    186186        in.numberofcorners=3;
    187187       
    188         in.trianglelist = (int *) xmalloc(3*in.numberoftriangles * sizeof(int));
     188        in.trianglelist = (int *) mxMalloc(3*in.numberoftriangles * sizeof(int));
    189189        for(i=0;i<in.numberoftriangles;i++){
    190190                for(j=0;j<3;j++){
     
    192192                }
    193193        }
    194         in.triangleattributelist = (REAL *) xmalloc(in.numberoftriangles * in.numberoftriangleattributes * sizeof(REAL));
     194        in.triangleattributelist = (REAL *) mxMalloc(in.numberoftriangles * in.numberoftriangleattributes * sizeof(REAL));
    195195        for(i=0;i<in.numberoftriangles;i++){
    196196                in.triangleattributelist[i]=0.0;
    197197        }
    198         in.trianglearealist = (REAL *) xmalloc(in.numberoftriangles * sizeof(REAL));
     198        in.trianglearealist = (REAL *) mxMalloc(in.numberoftriangles * sizeof(REAL));
    199199        for(i=0;i<in.numberoftriangles;i++){
    200200                in.trianglearealist[i]=area[i];
     
    203203        in.numberofpoints=nods;
    204204        in.numberofpointattributes=1;
    205         in.pointlist = (REAL *) xmalloc(in.numberofpoints * 2 * sizeof(REAL));
     205        in.pointlist = (REAL *) mxMalloc(in.numberofpoints * 2 * sizeof(REAL));
    206206        for (i=0;i<nods;i++){
    207207                in.pointlist[2*i+0]=x_in[i];
    208208                in.pointlist[2*i+1]=y_in[i];
    209209        }
    210         in.pointattributelist = (REAL *) xmalloc(in.numberofpoints * in.numberofpointattributes * sizeof(REAL));
     210        in.pointattributelist = (REAL *) mxMalloc(in.numberofpoints * in.numberofpointattributes * sizeof(REAL));
    211211        for (i=0;i<nods;i++){
    212212                in.pointattributelist[i] = 0.0;
     
    214214
    215215        in.numberofsegments = num_seg;
    216         in.segmentlist = (int *) xmalloc(in.numberofsegments * 2 * sizeof(REAL));
     216        in.segmentlist = (int *) mxMalloc(in.numberofsegments * 2 * sizeof(REAL));
    217217        in.segmentmarkerlist = (int *) mxCalloc(in.numberofsegments,sizeof(int));
    218218        for (i=0;i<num_seg;i++){
     
    250250       
    251251        /*Allocate index, x and y: */
    252         index=(double*)xmalloc(3*out.numberoftriangles*sizeof(double));
    253         x=(double*)xmalloc(out.numberofpoints*sizeof(double));
    254         y=(double*)xmalloc(out.numberofpoints*sizeof(double));
    255         segments=(double*)xmalloc(3*out.numberofsegments*sizeof(double));
    256         segmentmarkerlist=(double*)xmalloc(out.numberofsegments*sizeof(double));
     252        index=(double*)mxMalloc(3*out.numberoftriangles*sizeof(double));
     253        x=(double*)mxMalloc(out.numberofpoints*sizeof(double));
     254        y=(double*)mxMalloc(out.numberofpoints*sizeof(double));
     255        segments=(double*)mxMalloc(3*out.numberofsegments*sizeof(double));
     256        segmentmarkerlist=(double*)mxMalloc(out.numberofsegments*sizeof(double));
    257257
    258258        for (i = 0; i < out.numberoftriangles; i++) {
Note: See TracChangeset for help on using the changeset viewer.