Forums

Memory problems

Started by thed...@yahoo.com July 24, 2008
I've recently ran into issues allocating memory for variables in my program. At some point, I allocate memory as follows.
BIIR = (float **)calloc(20,sizeof(float*));
if( BIIR == NULL )
{
return false;
}

for(i=0;i<20;i++)
{
BIIR[i] = (float *)calloc(5,sizeof(float));
if( BIIR[i] == NULL )
{
return false;
}
}

The function that these lines of code in returns a "false" since the program sees that the variable BIIR[i] is null (specifically BIIR[17]), which leads me to believe that there isn't enough memory to support this allocation.

Has anyone ever had issues where there isn't enough memory on the device to support all variables in a program? I'm using a PEP5416 with CCSv3.1 by the way.
--- In c..., thedoctor152003@... wrote:
>
> I've recently ran into issues allocating memory for variables in my
program. At some point, I allocate memory as follows.
> BIIR = (float **)calloc(20,sizeof(float*));
> if( BIIR == NULL )
> {
> return false;
> }
>
> for(i=0;i<20;i++)
> {
> BIIR[i] = (float *)calloc(5,sizeof(float));
> if( BIIR[i] == NULL )
> {
> return false;
> }
> }
>
> The function that these lines of code in returns a "false" since the
program sees that the variable BIIR[i] is null (specifically
BIIR[17]), which leads me to believe that there isn't enough memory to
support this allocation.
>
> Has anyone ever had issues where there isn't enough memory on the
device to support all variables in a program? I'm using a PEP5416
with CCSv3.1 by the way.
>

I doubt that your actually running out of actual memory. I think your
memory definitions just might need tweaked. Do you have a -heap option
in your linker command file? At the top of the linker command file,
you can put something like -heap 0x800, which specifies the size of
the heap. This is allocated in the .sysmem section, so make sure that
you allocate that section into memory somewhere. When you call
malloc, calloc, etc, it tries to allocate this memory from the heap.
If you have not specified a heap section, you should see behavior like
you are seeing right now. In your example, BIIR, the pointer to the
buffer, is going to be allocated as a normal variable (either in .bss
for global variables, or on the stack for local variables) But the
dynamically allocated stuff gets allocated in the heap space.

Regards,
Dan