- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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;
}
Solved! Go to Solution.
- Labels:
-
PSoC 5LP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I found a temporary solution to my problem, but I don't like it:
Instead of using the malloc-function I did it like this:
double **m4x4;
double * m4x4_ptr_array[4];
double m4x4_data[4][4];
int i;
for (i=0; i<4;i++) m4x4_ptr_array = &m4x4_data[-1];
m4x4 = &m4x4_ptr_array[-1];
If anybody has an idea why the malloc function gives a allocation failure, I am still interested in it!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Bob
Thank you for your answer! Heap Size? When I look in the .cydwr view, there is written: 0x80. What means this exactly?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
0x80 bytes for heap. A bit few. When you use sprintf increase that to 0x0200 (bytes)
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ok, I found here something about the heap. So when I increase this storage, some library-functions like sprinf and malloc have more space. So do I have increase this value, until these failures are disappeared? Do you know any rule how to dimension this value?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As I said: set the heap to as much memory as you need + 0x0200 bytes.
Bob