Topic : Problems with malloc()

Forum : 8051

Original Post
Post Information Post
April 9, 2007 - 12:41pm
Guest

Hi everybody!!

I am trying to use the function malloc() in a program:


BYTE *puntero_aux;
BYTE RxBUffer[25],aux[25];
BYTE size,i;
size=25;

puntero_aux=malloc(size);
for (i=0;i<25;i++)
{
*(puntero_aux)=RxBUffer[i];
aux[i]=*(puntero_aux);
puntero_aux=puntero_aux+1;


}
My program compile correctly but when I try to execute step by step in Debug (virtual Machine) when I arrive to malloc() the progrma can not leave the malloc() (infinity bucle)

Could someone helps me? I don't know if I can use this function with 8051?? I need to store a variable number of bytes and I need to pointer to the first byte to read it, after to the second,...

Replies
Post Information Post
+1
0
-1
April 9, 2007 - 3:56pm
Guest

I don't know if I can use this function with 8051??
you 'can' but not if you want any execution speed to speak of. The '51 architecture is such that implementing malloc will give you coding that is very ineffective.
I need to store a variable number of bytes
why not just have an array that can hold the max number of bytes/

Erik

+1
0
-1
April 9, 2007 - 6:15pm
Guest

Thanks Erik!

I have used malloc() with my training board and it works(the speed is not a big prolblem at the moment) but I have one doubt, with kind of data is the pointer that retrun x=(BYTE*) malloc()? because I am trying to see the value through serial port in my PC but the value is not correct.

Santi

+1
0
-1
April 9, 2007 - 7:04pm
Guest

why not just drop malloc and avoid all problems?

+1
0
-1
April 10, 2007 - 11:42am
Guest

yes, maybe I will drop malloc()

Thanks
Santi