PSoC5 malloc matrix

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hello

   

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=m[i-1]+ncol;

   

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

0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

why the malloc function gives a allocation failure  Did you put aside enough heap memory? in .cydwr view, system tab, set the heap to as much memory as you need + 0x0200 bytes.

   

 

   

Bob

View solution in original post

0 Likes
6 Replies