This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
大神们好:
我碰到一个关于heap的问题
当我把heap定义在L2时,使用malloc函数可以正常运行,定义的数据空间的地址和大小都符合预期,当申请的空间大小超出堆的大小时,会申请失败
在.cmd中将堆的大小定义成0x4000
-heap 0x4000
代码如下:
for(i = 0; i < 0x10; i++)
{
char *p = NULL;
p = malloc(i * 0x800);
if(p == NULL)
{
printf("malloc failed,size:0x%X\n", i * 0x800);
}
else
{
printf("malloc suc:@0x%p,size:0x%X\n", p, i * 0x800);
free(p);
}
}
打印结果如下:
malloc failed,size:0x0
malloc suc:@0x108233f8,size:0x800
malloc suc:@0x108233f8,size:0x1000
malloc suc:@0x108233f8,size:0x1800
malloc suc:@0x108233f8,size:0x2000
malloc suc:@0x108233f8,size:0x2800
malloc suc:@0x108233f8,size:0x3000
malloc suc:@0x108233f8,size:0x3800
malloc failed,size:0x4000
malloc failed,size:0x4800
malloc failed,size:0x5000
malloc failed,size:0x5800
malloc failed,size:0x6000
malloc failed,size:0x6800
malloc failed,size:0x7000
malloc failed,size:0x7800
但是将heap定义在DDR时,就不正常了,地址会一直累加,而且当定义的空间大小超出堆的大小时,仍然能够定义成功,甚至远远超出堆地址的定义范围。
malloc failed,size:0x0
malloc suc:@0x80000118,size:0x800
malloc suc:@0x80000920,size:0x1000
malloc suc:@0x80001928,size:0x1800
malloc suc:@0x80003130,size:0x2000
malloc suc:@0x80005138,size:0x2800
malloc suc:@0x80007940,size:0x3000
malloc suc:@0x8000a948,size:0x3800
malloc suc:@0x8000e150,size:0x4000
malloc suc:@0x80012158,size:0x4800
malloc suc:@0x80016960,size:0x5000
malloc suc:@0x8001b968,size:0x5800
malloc suc:@0x80021170,size:0x6000
malloc suc:@0x80027178,size:0x6800
malloc suc:@0x8002d980,size:0x7000
malloc suc:@0x80034988,size:0x7800
请问大神,这种情况要怎么处理呀?
是的,就是通过修改.sysmem来定义heap所在的空间的。目前排查到应该DDR初始化的问题,我用的是“5444.STK_C6657”里面keystone common里面的初始化程序。