我使用下面此方法在uCOS2.9中创建双向循环链表,程序却死在这里(内存足够),
struct Temp {unsigned char data;
struct Temp *pBefor;
struct Temp *pNext;};
struct Temp *head;
struct Temp *CreateTempBuff(unsigned short num)
{
struct Temp *pf,*pb,*phead;
unsigned short i=num;
for(;i>0;i--)
{
pb=(struct Temp *)malloc(sizeof(struct temp));
if(i==num)
pf=phead=pb;
else
{pf->pNext=pb;pb->pBefor=pf;}
if(i==1)
{pb->pNext=phead;phead->pBefor=pb;}
else
pb->pNext=NULL;
pf=pb;
}
return (phead);
}
不知是哪里出错了?
然后我又换了一种方法,使用系统的内存分配模块,如下:
struct Temp {unsigned char data;
struct Temp *pBefor;
struct Temp *pNext;};
OS_MEM *TempBuf;
struct Temp *head;
struct Temp *CreateTempBuff(unsigned short num)
{
INT8U *err;
struct Temp *pf,*pb,*phead;
unsigned short i=num;
for(;i>0;i--)
{
pb=(struct Temp *)OSMemGet(TempBuf,err);
if(i==num)
pf=phead=pb;
else
{pf->pNext=pb;pb->pBefor=pf;}
if(i==1)
{pb->pNext=phead;phead->pBefor=pb;}
else
pb->pNext=NULL;
pf=pb;
}
return (phead);
}
内存分区已在多任务启动之前建立并把指针给了 TempBuf,配置文件也已启动内存分区,可是程序仍然死在这里,求各位指点一下(补充一点,我使用的LPC1768,同时还嵌有uCGUI) |