6 Replies Latest reply on May 18, 2016 10:24 AM by JoMe_264151

    PSoC5 malloc matrix



      I try to use matrices in PSoC5. Therefore I found good basic routines to work with matrices. But I get a allocation failure when I try to allocate a 4x4 double matrix. Do anyone know what I have to improve to that?


      Here the code to allocate the matrix:


      /*Allocate a double matrix with subscript range m[nrl..nrh][ncl..nch]*/


      double **matrix(long nrl, long nrh, long ncl, long nch)
          long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
          double **m;


          /* allocate pointers to rows */
          m=(double **) malloc((size_t)((nrow+NR_END)*sizeof(double*)));
          if (!m) pr_error("allocation failure 1 in LINALG_dmatrix()");
          m += NR_END;
          m -= nrl;


          /* allocate rows and set pointers to them */
          m[nrl]=(double *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(double)));
          if (!m[nrl]) pr_error("allocation failure 2 in LINALG_dmatrix()");
          m[nrl] += NR_END;
          m[nrl] -= ncl;


          for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;


          /* return pointer to array of pointers to rows */
          return m;