Changeset 12037


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

Allocating matlab's variable using Matlab's memory manager

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/matlab/io/WriteMatlabData.cpp

    r12022 r12037  
    3333                #endif
    3434
    35                 /*Now transpose the matrix: */
     35                /*Now transpose the matrix and allocate with Matlab's memory manager: */
    3636                tmatrix_ptr=(double*)mxMalloc(rows*cols*sizeof(double));
    3737                for(i=0;i<cols;i++){
     
    6363        mxArray* dataref=NULL;
    6464        double*  vector_ptr=NULL;
     65        double*  vector_ptr2=NULL;
    6566        int      rows;
    6667       
     
    7475                #endif
    7576               
    76                 /*now create the matlab vector: */
     77                /*now create the matlab vector with Matlab's memory manager */
     78                vector_ptr2=(double*)mxMalloc(rows*sizeof(double));
     79                for(int i=0;i<rows;i++) vector_ptr2[i]=vector_ptr[i];
     80
    7781                dataref = mxCreateDoubleMatrix(0,0,mxREAL);                         
    7882                mxSetM(dataref,rows);
    7983                mxSetN(dataref,1);                                                                                         
    80                 mxSetPr(dataref,vector_ptr);           
     84                mxSetPr(dataref,vector_ptr2);           
    8185        }
    8286        else{
    8387                dataref = mxCreateDoubleMatrix(0,0,mxREAL);
    8488        }
     89
     90        /*Clean-up and return*/
     91        xfree((void**)&vector_ptr);
    8592        *pdataref=dataref;
    86 
    8793}
    8894/*}}}*/
Note: See TracChangeset for help on using the changeset viewer.