之前在网上看过一篇文章:C51单片机动态内存分配;
尝试文章里的方法分配内存;出现了一些问题,在这里写出来共同分析一下;
1
1.1 静态数组定义
/********************************************************************************************************/
/* 系统随机分配一个数组,将数组的首地址和数组的长度N作为堆区的空间参数 */
static uint8 xdata membuff[256];
/********************************************************************************************************/
1.2 初始化数组
memset(membuff, 0, sizeof(membuff));
1.3 使用函数 void init_mempool (void _MALLOC_MEM_ *p, unsigned int size) 来初始化 membuff[] 数组;得到一个可以动态分配的堆
init_mempool(membuff, sizeof(membuff));
1.4 这里我们在定义一个打印指针地址及其所指内容的函数;每行打印8个
**********************************************************************************************************
**功能描述: 打印指针的地址及其所指向的内容
**入口参数:
** @*addr --- -要打印的地址起始位置
** @len --- -要打印的地址的长度
**出口参数: 无
**-------------------------=------------------------------------
**函数注释: 无
**********************************************************************************************************
*/
void print_reg_addr(uint8 *addr, uint16 len)
{
uint8 xdata tmp[20];
uint16 xdata i;
/* 打印回车 */
uart_print_enter(UART1);
memset(tmp, 0, sizeof(tmp));
for (i=0; i<len; i++)
{
sprintf(tmp,"%p=0x%-4.2X ",addr,(uint16)*addr++);
uart_print_string(UART1, tmp);
memset(tmp, 0, sizeof(tmp));
if ((i+1)%8 == 0)
{
uart_print_enter(UART1);
}
}
uart_print_enter(UART1);
}
得到如下的结果
x:01c8=0x00 x:01c9=0x00 x:01ca=0x00 x:01cb=0xFC x:01cc=0x00 x:01cd=0x00 x:01ce=0x00 x:01cf=0x00
x:01d0=0x00 x:01d1=0x00 x:01d2=0x00 x:01d3=0x00 x:01d4=0x00 x:01d5=0x00 x:01d6=0x00 x:01d7=0x00
x:01d8=0x00 x:01d9=0x00 x:01da=0x00 x:01db=0x00 x:01dc=0x00 x:01dd=0x00 x:01de=0x00 x:01df=0x00
x:01e0=0x00 x:01e1=0x00 x:01e2=0x00 x:01e3=0x00 x:01e4=0x00 x:01e5=0x00 x:01e6=0x00 x:01e7=0x00
x:01e8=0x00 x:01e9=0x00 x:01ea=0x00 x:01eb=0x00 x:01ec=0x00 x:01ed=0x00 x:01ee=0x00 x:01ef=0x00
x:01f0=0x00 x:01f1=0x00 x:01f2=0x00 x:01f3=0x00 x:01f4=0x00 x:01f5=0x00 x:01f6=0x00 x:01f7=0x00
x:01f8=0x00 x:01f9=0x00 x:01fa=0x00 x:01fb=0x00 x:01fc=0x00 x:01fd=0x00 x:01fe=0x00 x:01ff=0x00
x:0200=0x00 x:0201=0x00 x:0202=0x00 x:0203=0x00 x:0204=0x00 x:0205=0x00 x:0206=0x00 x:0207=0x00
x:0208=0x00 x:0209=0x00 x:020a=0x00 x:020b=0x00 x:020c=0x00 x:020d=0x00 x:020e=0x00 x:020f=0x00
x:0210=0x00 x:0211=0x00 x:0212=0x00 x:0213=0x00 x:0214=0x00 x:0215=0x00 x:0216=0x00 x:0217=0x00
x:0218=0x00 x:0219=0x00 x:021a=0x00 x:021b=0x00 x:021c=0x00 x:021d=0x00 x:021e=0x00 x:021f=0x00
x:0220=0x00 x:0221=0x00 x:0222=0x00 x:0223=0x00 x:0224=0x00 x:0225=0x00 x:0226=0x00 x:0227=0x00
x:0228=0x00 x:0229=0x00 x:022a=0x00 x:022b=0x00 x:022c=0x00 x:022d=0x00 x:022e=0x00 x:022f=0x00
x:0230=0x00 x:0231=0x00 x:0232=0x00 x:0233=0x00 x:0234=0x00 x:0235=0x00 x:0236=0x00 x:0237=0x00
x:0238=0x00 x:0239=0x00 x:023a=0x00 x:023b=0x00 x:023c=0x00 x:023d=0x00 x:023e=0x00 x:023f=0x00
x:0240=0x00 x:0241=0x00 x:0242=0x00 x:0243=0x00 x:0244=0x00 x:0245=0x00 x:0246=0x00 x:0247=0x00
x:0248=0x00 x:0249=0x00 x:024a=0x00 x:024b=0x00 x:024c=0x00 x:024d=0x00 x:024e=0x00 x:024f=0x00
x:0250=0x00 x:0251=0x00 x:0252=0x00 x:0253=0x00 x:0254=0x00 x:0255=0x00 x:0256=0x00 x:0257=0x00
x:0258=0x00 x:0259=0x00 x:025a=0x00 x:025b=0x00 x:025c=0x00 x:025d=0x00 x:025e=0x00 x:025f=0x00
x:0260=0x00 x:0261=0x00 x:0262=0x00 x:0263=0x00 x:0264=0x00 x:0265=0x00 x:0266=0x00 x:0267=0x00
x:0268=0x00 x:0269=0x00 x:026a=0x00 x:026b=0x00 x:026c=0x00 x:026d=0x00 x:026e=0x00 x:026f=0x00
x:0270=0x00 x:0271=0x00 x:0272=0x00 x:0273=0x00 x:0274=0x00 x:0275=0x00 x:0276=0x00 x:0277=0x00
x:0278=0x00 x:0279=0x00 x:027a=0x00 x:027b=0x00 x:027c=0x00 x:027d=0x00 x:027e=0x00 x:027f=0x00
x:0280=0x00 x:0281=0x00 x:0282=0x00 x:0283=0x00 x:0284=0x00 x:0285=0x00 x:0286=0x00 x:0287=0x00
x:0288=0x00 x:0289=0x00 x:028a=0x00 x:028b=0x00 x:028c=0x00 x:028d=0x00 x:028e=0x00 x:028f=0x00
x:0290=0x00 x:0291=0x00 x:0292=0x00 x:0293=0x00 x:0294=0x00 x:0295=0x00 x:0296=0x00 x:0297=0x00
x:0298=0x00 x:0299=0x00 x:029a=0x00 x:029b=0x00 x:029c=0x00 x:029d=0x00 x:029e=0x00 x:029f=0x00
x:02a0=0x00 x:02a1=0x00 x:02a2=0x00 x:02a3=0x00 x:02a4=0x00 x:02a5=0x00 x:02a6=0x00 x:02a7=0x00
x:02a8=0x00 x:02a9=0x00 x:02aa=0x00 x:02ab=0x00 x:02ac=0x00 x:02ad=0x00 x:02ae=0x00 x:02af=0x00
x:02b0=0x00 x:02b1=0x00 x:02b2=0x00 x:02b3=0x00 x:02b4=0x00 x:02b5=0x00 x:02b6=0x00 x:02b7=0x00
x:02b8=0x00 x:02b9=0x00 x:02ba=0x00 x:02bb=0x00 x:02bc=0x00 x:02bd=0x00 x:02be=0x00 x:02bf=0x00
x:02c0=0x00 x:02c1=0x00 x:02c2=0x00 x:02c3=0x00 x:02c4=0x00 x:02c5=0x00 x:02c6=0x00 x:02c7=0x00
分析:静态数组 membuff[] 随机分配到的起始地址为 0x01c8,即
membuff[0]的地址为0x01c8,membuff[255]的地址为0x02c7;
在这里需要注意的是上面输出数据的 x:01cb 及其前面的3个元素;
x:01c8=0x00 x:01c9=0x00 x:01ca=0x00 x:01cb=0xFC
其中 x:01cb = 0xFC 这个是函数
init_mempool() 使用之后才有的值,这个值的十进制是 252;这个实际所表示的意思是有252个字节可以供 malloc 函数申请;若此时调用函数 malloc(253),函数返回 NULL;
2 如何使用 malloc calloc free 函数等
2.1 malloc申请一块64字节的内存,并打印其地址及内容
lp1 = malloc(64);
if (NULL != lp1)
{
uart_print_debug_string(UART1,"lp1 malloc ok");
print_reg_addr(lp1,64);
//free(lp1);
}
else
{
uart_print_enter(UART1);
uart_print_debug_string(UART1,"lp1 malloc error");
}
输出结果如下
lp1 malloc ok
x:0288=0x00 x:0289=0x00 x:028a=0x00 x:028b=0x00 x:028c=0x00 x:028d=0x00 x:028e=0x00 x:028f=0x00
x:0290=0x00 x:0291=0x00 x:0292=0x00 x:0293=0x00 x:0294=0x00 x:0295=0x00 x:0296=0x00 x:0297=0x00
x:0298=0x00 x:0299=0x00 x:029a=0x00 x:029b=0x00 x:029c=0x00 x:029d=0x00 x:029e=0x00 x:029f=0x00
x:02a0=0x00 x:02a1=0x00 x:02a2=0x00 x:02a3=0x00 x:02a4=0x00 x:02a5=0x00 x:02a6=0x00 x:02a7=0x00
x:02a8=0x00 x:02a9=0x00 x:02aa=0x00 x:02ab=0x00 x:02ac=0x00 x:02ad=0x00 x:02ae=0x00 x:02af=0x00
x:02b0=0x00 x:02b1=0x00 x:02b2=0x00 x:02b3=0x00 x:02b4=0x00 x:02b5=0x00 x:02b6=0x00 x:02b7=0x00
x:02b8=0x00 x:02b9=0x00 x:02ba=0x00 x:02bb=0x00 x:02bc=0x00 x:02bd=0x00 x:02be=0x00 x:02bf=0x00
x:02c0=0x00 x:02c1=0x00 x:02c2=0x00 x:02c3=0x00 x:02c4=0x00 x:02c5=0x00 x:02c6=0x00 x:02c7=0x00
到此都没有问题, 得到的字节数为 (0x02c7 - 0x0288) + 1 = 0x40(64);
2.2 现在;我们在申请3次,但每次都不释放内存,打印出每次分配到的内存,然后在打印整个静态数组
lp1 = malloc(64);
if (NULL != lp1)
{
uart_print_debug_string(UART1,"lp1 malloc ok");
print_reg_addr(lp1,64);
//free(lp1);
}
else
{
uart_print_enter(UART1);
uart_print_debug_string(UART1,"lp1 malloc error");
}
lp2 = malloc(64);
if (NULL != lp2)
{
uart_print_debug_string(UART1,"lp2 malloc ok");
print_reg_addr(lp2,64);
//free(lp2);
}
else
{
uart_print_enter(UART1);
uart_print_debug_string(UART1,"lp2 malloc error");
}
lp3 = malloc(64);
if (NULL != lp3)
{
uart_print_debug_string(UART1,"lp3 malloc ok");
print_reg_addr(lp3,64);
//free(lp3);
}
else
{
uart_print_enter(UART1);
uart_print_debug_string(UART1,"lp3 malloc error");
}
print_reg_addr(membuff,sizeof(membuff));
lp1 malloc ok
x:0288=0x00 x:0289=0x00 x:028a=0x00 x:028b=0x00 x:028c=0x00 x:028d=0x00 x:028e=0x00 x:028f=0x00
x:0290=0x00 x:0291=0x00 x:0292=0x00 x:0293=0x00 x:0294=0x00 x:0295=0x00 x:0296=0x00 x:0297=0x00
x:0298=0x00 x:0299=0x00 x:029a=0x00 x:029b=0x00 x:029c=0x00 x:029d=0x00 x:029e=0x00 x:029f=0x00
x:02a0=0x00 x:02a1=0x00 x:02a2=0x00 x:02a3=0x00 x:02a4=0x00 x:02a5=0x00 x:02a6=0x00 x:02a7=0x00
x:02a8=0x00 x:02a9=0x00 x:02aa=0x00 x:02ab=0x00 x:02ac=0x00 x:02ad=0x00 x:02ae=0x00 x:02af=0x00
x:02b0=0x00 x:02b1=0x00 x:02b2=0x00 x:02b3=0x00 x:02b4=0x00 x:02b5=0x00 x:02b6=0x00 x:02b7=0x00
x:02b8=0x00 x:02b9=0x00 x:02ba=0x00 x:02bb=0x00 x:02bc=0x00 x:02bd=0x00 x:02be=0x00 x:02bf=0x00
x:02c0=0x00 x:02c1=0x00 x:02c2=0x00 x:02c3=0x00 x:02c4=0x00 x:02c5=0x00 x:02c6=0x00 x:02c7=0x00
lp2 malloc ok
x:0244=0x00 x:0245=0x00 x:0246=0x00 x:0247=0x00 x:0248=0x00 x:0249=0x00 x:024a=0x00 x:024b=0x00
x:024c=0x00 x:024d=0x00 x:024e=0x00 x:024f=0x00 x:0250=0x00 x:0251=0x00 x:0252=0x00 x:0253=0x00
x:0254=0x00 x:0255=0x00 x:0256=0x00 x:0257=0x00 x:0258=0x00 x:0259=0x00 x:025a=0x00 x:025b=0x00
x:025c=0x00 x:025d=0x00 x:025e=0x00 x:025f=0x00 x:0260=0x00 x:0261=0x00 x:0262=0x00 x:0263=0x00
x:0264=0x00 x:0265=0x00 x:0266=0x00 x:0267=0x00 x:0268=0x00 x:0269=0x00 x:026a=0x00 x:026b=0x00
x:026c=0x00 x:026d=0x00 x:026e=0x00 x:026f=0x00 x:0270=0x00 x:0271=0x00 x:0272=0x00 x:0273=0x00
x:0274=0x00 x:0275=0x00 x:0276=0x00 x:0277=0x00 x:0278=0x00 x:0279=0x00 x:027a=0x00 x:027b=0x00
x:027c=0x00 x:027d=0x00 x:027e=0x00 x:027f=0x00 x:0280=0x00 x:0281=0x00 x:0282=0x00 x:0283=0x00
lp3 malloc ok
x:0200=0x00 x:0201=0x00 x:0202=0x00 x:0203=0x00 x:0204=0x00 x:0205=0x00 x:0206=0x00 x:0207=0x00
x:0208=0x00 x:0209=0x00 x:020a=0x00 x:020b=0x00 x:020c=0x00 x:020d=0x00 x:020e=0x00 x:020f=0x00
x:0210=0x00 x:0211=0x00 x:0212=0x00 x:0213=0x00 x:0214=0x00 x:0215=0x00 x:0216=0x00 x:0217=0x00
x:0218=0x00 x:0219=0x00 x:021a=0x00 x:021b=0x00 x:021c=0x00 x:021d=0x00 x:021e=0x00 x:021f=0x00
x:0220=0x00 x:0221=0x00 x:0222=0x00 x:0223=0x00 x:0224=0x00 x:0225=0x00 x:0226=0x00 x:0227=0x00
x:0228=0x00 x:0229=0x00 x:022a=0x00 x:022b=0x00 x:022c=0x00 x:022d=0x00 x:022e=0x00 x:022f=0x00
x:0230=0x00 x:0231=0x00 x:0232=0x00 x:0233=0x00 x:0234=0x00 x:0235=0x00 x:0236=0x00 x:0237=0x00
x:0238=0x00 x:0239=0x00 x:023a=0x00 x:023b=0x00 x:023c=0x00 x:023d=0x00 x:023e=0x00 x:023f=0x00
x:01c8=0x00 x:01c9=0x00 x:01ca=0x00 x:01cb=0x30 x:01cc=0x00 x:01cd=0x00 x:01ce=0x00 x:01cf=0x00
x:01d0=0x00 x:01d1=0x00 x:01d2=0x00 x:01d3=0x00 x:01d4=0x00 x:01d5=0x00 x:01d6=0x00 x:01d7=0x00
x:01d8=0x00 x:01d9=0x00 x:01da=0x00 x:01db=0x00 x:01dc=0x00 x:01dd=0x00 x:01de=0x00 x:01df=0x00
x:01e0=0x00 x:01e1=0x00 x:01e2=0x00 x:01e3=0x00 x:01e4=0x00 x:01e5=0x00 x:01e6=0x00 x:01e7=0x00
x:01e8=0x00 x:01e9=0x00 x:01ea=0x00 x:01eb=0x00 x:01ec=0x00 x:01ed=0x00 x:01ee=0x00 x:01ef=0x00
x:01f0=0x00 x:01f1=0x00 x:01f2=0x00 x:01f3=0x00 x:01f4=0x00 x:01f5=0x00 x:01f6=0x00 x:01f7=0x00
x:01f8=0x00 x:01f9=0x00 x:01fa=0x00 x:01fb=0x00 x:01fc=0x00 x:01fd=0x00 x:01fe=0x00 x:01ff=0x40
x:0200=0x00 x:0201=0x00 x:0202=0x00 x:0203=0x00 x:0204=0x00 x:0205=0x00 x:0206=0x00 x:0207=0x00
x:0208=0x00 x:0209=0x00 x:020a=0x00 x:020b=0x00 x:020c=0x00 x:020d=0x00 x:020e=0x00 x:020f=0x00
x:0210=0x00 x:0211=0x00 x:0212=0x00 x:0213=0x00 x:0214=0x00 x:0215=0x00 x:0216=0x00 x:0217=0x00
x:0218=0x00 x:0219=0x00 x:021a=0x00 x:021b=0x00 x:021c=0x00 x:021d=0x00 x:021e=0x00 x:021f=0x00
x:0220=0x00 x:0221=0x00 x:0222=0x00 x:0223=0x00 x:0224=0x00 x:0225=0x00 x:0226=0x00 x:0227=0x00
x:0228=0x00 x:0229=0x00 x:022a=0x00 x:022b=0x00 x:022c=0x00 x:022d=0x00 x:022e=0x00 x:022f=0x00
x:0230=0x00 x:0231=0x00 x:0232=0x00 x:0233=0x00 x:0234=0x00 x:0235=0x00 x:0236=0x00 x:0237=0x00
x:0238=0x00 x:0239=0x00 x:023a=0x00 x:023b=0x00 x:023c=0x00 x:023d=0x00 x:023e=0x00 x:023f=0x00
x:0240=0x00 x:0241=0x00 x:0242=0x00 x:0243=0x40 x:0244=0x00 x:0245=0x00 x:0246=0x00 x:0247=0x00
x:0248=0x00 x:0249=0x00 x:024a=0x00 x:024b=0x00 x:024c=0x00 x:024d=0x00 x:024e=0x00 x:024f=0x00
x:0250=0x00 x:0251=0x00 x:0252=0x00 x:0253=0x00 x:0254=0x00 x:0255=0x00 x:0256=0x00 x:0257=0x00
x:0258=0x00 x:0259=0x00 x:025a=0x00 x:025b=0x00 x:025c=0x00 x:025d=0x00 x:025e=0x00 x:025f=0x00
x:0260=0x00 x:0261=0x00 x:0262=0x00 x:0263=0x00 x:0264=0x00 x:0265=0x00 x:0266=0x00 x:0267=0x00
x:0268=0x00 x:0269=0x00 x:026a=0x00 x:026b=0x00 x:026c=0x00 x:026d=0x00 x:026e=0x00 x:026f=0x00
x:0270=0x00 x:0271=0x00 x:0272=0x00 x:0273=0x00 x:0274=0x00 x:0275=0x00 x:0276=0x00 x:0277=0x00
x:0278=0x00 x:0279=0x00 x:027a=0x00 x:027b=0x00 x:027c=0x00 x:027d=0x00 x:027e=0x00 x:027f=0x00
x:0280=0x00 x:0281=0x00 x:0282=0x00 x:0283=0x00 x:0284=0x00 x:0285=0x00 x:0286=0x00 x:0287=0x40
x:0288=0x00 x:0289=0x00 x:028a=0x00 x:028b=0x00 x:028c=0x00 x:028d=0x00 x:028e=0x00 x:028f=0x00
x:0290=0x00 x:0291=0x00 x:0292=0x00 x:0293=0x00 x:0294=0x00 x:0295=0x00 x:0296=0x00 x:0297=0x00
x:0298=0x00 x:0299=0x00 x:029a=0x00 x:029b=0x00 x:029c=0x00 x:029d=0x00 x:029e=0x00 x:029f=0x00
x:02a0=0x00 x:02a1=0x00 x:02a2=0x00 x:02a3=0x00 x:02a4=0x00 x:02a5=0x00 x:02a6=0x00 x:02a7=0x00
x:02a8=0x00 x:02a9=0x00 x:02aa=0x00 x:02ab=0x00 x:02ac=0x00 x:02ad=0x00 x:02ae=0x00 x:02af=0x00
x:02b0=0x00 x:02b1=0x00 x:02b2=0x00 x:02b3=0x00 x:02b4=0x00 x:02b5=0x00 x:02b6=0x00 x:02b7=0x00
x:02b8=0x00 x:02b9=0x00 x:02ba=0x00 x:02bb=0x00 x:02bc=0x00 x:02bd=0x00 x:02be=0x00 x:02bf=0x00
x:02c0=0x00 x:02c1=0x00 x:02c2=0x00 x:02c3=0x00 x:02c4=0x00 x:02c5=0x00 x:02c6=0x00 x:02c7=0x00
注意最后面这个输出的红的字体部分可以得到如下结论,每次分配完空间后,会使用4个字节来保存信息,
x:0284=0x00 x:0285=0x00 x:0286=0x00 x:0287=0x40 保存了 lp1的分配了 0x40个字节的信息
x:0240=0x00 x:0241=0x00 x:0242=0x00 x:0243=0x40 保存了 lp2的分配了 0x40个字节的信息
x:01fc=0x00 x:01fd=0x00 x:01fe=0x00 x:01ff=0x40 保存了 lp3的分配了 0x40个字节的信息
最后:
x:01c8=0x00 x:01c9=0x00 x:01ca=0x00 x:01cb=0x30 这个保存了数组中仍能被申请的内存的数量
0x30 = 252 - (64 + 4) * 3 = 48;
备注:经过多次的测试得到如下结论
每次 malloc 之后,会预留4个字节保存消息
而使用 init_mempool 时,假如初始化的数组元素大于256,则会有5个字节来保存,实际应该是 3 + n 个字节,n要看分配的内存的数量来定;
而且每次使用malloc后,保存剩余字节数的 3 + n 个字节 不会随剩余字节数的数量变化;假如一开始是5个,到最后就算还有1个字节可用,也是最初的5个字节来保存;
总结:到目前为止都没有出现问题;
3
现在问题来了:当申请的内存数大于数组可供使用的内存大小时(252),会出现什么问题呢;
3.1 假如第一次申请 64个使用后立即释放掉,第二次申请200个,会发生什么变化呢
lp1 malloc ok
x:0288=0x00 x:0289=0x00 x:028a=0x00 x:028b=0x00 x:028c=0x00 x:028d=0x00 x:028e=0x00 x:028f=0x00
x:0290=0x00 x:0291=0x00 x:0292=0x00 x:0293=0x00 x:0294=0x00 x:0295=0x00 x:0296=0x00 x:0297=0x00
x:0298=0x00 x:0299=0x00 x:029a=0x00 x:029b=0x00 x:029c=0x00 x:029d=0x00 x:029e=0x00 x:029f=0x00
x:02a0=0x00 x:02a1=0x00 x:02a2=0x00 x:02a3=0x00 x:02a4=0x00 x:02a5=0x00 x:02a6=0x00 x:02a7=0x00
x:02a8=0x00 x:02a9=0x00 x:02aa=0x00 x:02ab=0x00 x:02ac=0x00 x:02ad=0x00 x:02ae=0x00 x:02af=0x00
x:02b0=0x00 x:02b1=0x00 x:02b2=0x00 x:02b3=0x00 x:02b4=0x00 x:02b5=0x00 x:02b6=0x00 x:02b7=0x00
x:02b8=0x00 x:02b9=0x00 x:02ba=0x00 x:02bb=0x00 x:02bc=0x00 x:02bd=0x00 x:02be=0x00 x:02bf=0x00
x:02c0=0x00 x:02c1=0x00 x:02c2=0x00 x:02c3=0x00 x:02c4=0x00 x:02c5=0x00 x:02c6=0x00 x:02c7=0x00
x:01c8=0x00 x:01c9=0x00 x:01ca=0x00 x:01cb=0xFC x:01cc=0x00 x:01cd=0x00 x:01ce=0x00 x:01cf=0x00
x:01d0=0x00 x:01d1=0x00 x:01d2=0x00 x:01d3=0x00 x:01d4=0x00 x:01d5=0x00 x:01d6=0x00 x:01d7=0x00
x:01d8=0x00 x:01d9=0x00 x:01da=0x00 x:01db=0x00 x:01dc=0x00 x:01dd=0x00 x:01de=0x00 x:01df=0x00
x:01e0=0x00 x:01e1=0x00 x:01e2=0x00 x:01e3=0x00 x:01e4=0x00 x:01e5=0x00 x:01e6=0x00 x:01e7=0x00
x:01e8=0x00 x:01e9=0x00 x:01ea=0x00 x:01eb=0x00 x:01ec=0x00 x:01ed=0x00 x:01ee=0x00 x:01ef=0x00
x:01f0=0x00 x:01f1=0x00 x:01f2=0x00 x:01f3=0x00 x:01f4=0x00 x:01f5=0x00 x:01f6=0x00 x:01f7=0x00
x:01f8=0x00 x:01f9=0x00 x:01fa=0x00 x:01fb=0x00 x:01fc=0x00 x:01fd=0x00 x:01fe=0x00 x:01ff=0x00
x:0200=0x00 x:0201=0x00 x:0202=0x00 x:0203=0x00 x:0204=0x00 x:0205=0x00 x:0206=0x00 x:0207=0x00
x:0208=0x00 x:0209=0x00 x:020a=0x00 x:020b=0x00 x:020c=0x00 x:020d=0x00 x:020e=0x00 x:020f=0x00
x:0210=0x00 x:0211=0x00 x:0212=0x00 x:0213=0x00 x:0214=0x00 x:0215=0x00 x:0216=0x00 x:0217=0x00
x:0218=0x00 x:0219=0x00 x:021a=0x00 x:021b=0x00 x:021c=0x00 x:021d=0x00 x:021e=0x00 x:021f=0x00
x:0220=0x00 x:0221=0x00 x:0222=0x00 x:0223=0x00 x:0224=0x00 x:0225=0x00 x:0226=0x00 x:0227=0x00
x:0228=0x00 x:0229=0x00 x:022a=0x00 x:022b=0x00 x:022c=0x00 x:022d=0x00 x:022e=0x00 x:022f=0x00
x:0230=0x00 x:0231=0x00 x:0232=0x00 x:0233=0x00 x:0234=0x00 x:0235=0x00 x:0236=0x00 x:0237=0x00
x:0238=0x00 x:0239=0x00 x:023a=0x00 x:023b=0x00 x:023c=0x00 x:023d=0x00 x:023e=0x00 x:023f=0x00
x:0240=0x00 x:0241=0x00 x:0242=0x00 x:0243=0x00 x:0244=0x00 x:0245=0x00 x:0246=0x00 x:0247=0x00
x:0248=0x00 x:0249=0x00 x:024a=0x00 x:024b=0x00 x:024c=0x00 x:024d=0x00 x:024e=0x00 x:024f=0x00
x:0250=0x00 x:0251=0x00 x:0252=0x00 x:0253=0x00 x:0254=0x00 x:0255=0x00 x:0256=0x00 x:0257=0x00
x:0258=0x00 x:0259=0x00 x:025a=0x00 x:025b=0x00 x:025c=0x00 x:025d=0x00 x:025e=0x00 x:025f=0x00
x:0260=0x00 x:0261=0x00 x:0262=0x00 x:0263=0x00 x:0264=0x00 x:0265=0x00 x:0266=0x00 x:0267=0x00
x:0268=0x00 x:0269=0x00 x:026a=0x00 x:026b=0x00 x:026c=0x00 x:026d=0x00 x:026e=0x00 x:026f=0x00
x:0270=0x00 x:0271=0x00 x:0272=0x00 x:0273=0x00 x:0274=0x00 x:0275=0x00 x:0276=0x00 x:0277=0x00
x:0278=0x00 x:0279=0x00 x:027a=0x00 x:027b=0x00 x:027c=0x00 x:027d=0x00 x:027e=0x00 x:027f=0x00
x:0280=0x00 x:0281=0x00 x:0282=0x00 x:0283=0x00 x:0284=0x00 x:0285=0x00 x:0286=0x00 x:0287=0x40
x:0288=0x00 x:0289=0x00 x:028a=0x00 x:028b=0x00 x:028c=0x00 x:028d=0x00 x:028e=0x00 x:028f=0x00
x:0290=0x00 x:0291=0x00 x:0292=0x00 x:0293=0x00 x:0294=0x00 x:0295=0x00 x:0296=0x00 x:0297=0x00
x:0298=0x00 x:0299=0x00 x:029a=0x00 x:029b=0x00 x:029c=0x00 x:029d=0x00 x:029e=0x00 x:029f=0x00
x:02a0=0x00 x:02a1=0x00 x:02a2=0x00 x:02a3=0x00 x:02a4=0x00 x:02a5=0x00 x:02a6=0x00 x:02a7=0x00
x:02a8=0x00 x:02a9=0x00 x:02aa=0x00 x:02ab=0x00 x:02ac=0x00 x:02ad=0x00 x:02ae=0x00 x:02af=0x00
x:02b0=0x00 x:02b1=0x00 x:02b2=0x00 x:02b3=0x00 x:02b4=0x00 x:02b5=0x00 x:02b6=0x00 x:02b7=0x00
x:02b8=0x00 x:02b9=0x00 x:02ba=0x00 x:02bb=0x00 x:02bc=0x00 x:02bd=0x00 x:02be=0x00 x:02bf=0x00
x:02c0=0x00 x:02c1=0x00 x:02c2=0x00 x:02c3=0x00 x:02c4=0x00 x:02c5=0x00 x:02c6=0x00 x:02c7=0x00
lp2 malloc ok
x:0200=0x00 x:0201=0x00 x:0202=0x00 x:0203=0x00 x:0204=0x00 x:0205=0x00 x:0206=0x00 x:0207=0x00
x:0208=0x00 x:0209=0x00 x:020a=0x00 x:020b=0x00 x:020c=0x00 x:020d=0x00 x:020e=0x00 x:020f=0x00
x:0210=0x00 x:0211=0x00 x:0212=0x00 x:0213=0x00 x:0214=0x00 x:0215=0x00 x:0216=0x00 x:0217=0x00
x:0218=0x00 x:0219=0x00 x:021a=0x00 x:021b=0x00 x:021c=0x00 x:021d=0x00 x:021e=0x00 x:021f=0x00
x:0220=0x00 x:0221=0x00 x:0222=0x00 x:0223=0x00 x:0224=0x00 x:0225=0x00 x:0226=0x00 x:0227=0x00
x:0228=0x00 x:0229=0x00 x:022a=0x00 x:022b=0x00 x:022c=0x00 x:022d=0x00 x:022e=0x00 x:022f=0x00
x:0230=0x00 x:0231=0x00 x:0232=0x00 x:0233=0x00 x:0234=0x00 x:0235=0x00 x:0236=0x00 x:0237=0x00
x:0238=0x00 x:0239=0x00 x:023a=0x00 x:023b=0x00 x:023c=0x00 x:023d=0x00 x:023e=0x00 x:023f=0x00
x:0240=0x00 x:0241=0x00 x:0242=0x00 x:0243=0x00 x:0244=0x00 x:0245=0x00 x:0246=0x00 x:0247=0x00
x:0248=0x00 x:0249=0x00 x:024a=0x00 x:024b=0x00 x:024c=0x00 x:024d=0x00 x:024e=0x00 x:024f=0x00
x:0250=0x00 x:0251=0x00 x:0252=0x00 x:0253=0x00 x:0254=0x00 x:0255=0x00 x:0256=0x00 x:0257=0x00
x:0258=0x00 x:0259=0x00 x:025a=0x00 x:025b=0x00 x:025c=0x00 x:025d=0x00 x:025e=0x00 x:025f=0x00
x:0260=0x00 x:0261=0x00 x:0262=0x00 x:0263=0x00 x:0264=0x00 x:0265=0x00 x:0266=0x00 x:0267=0x00
x:0268=0x00 x:0269=0x00 x:026a=0x00 x:026b=0x00 x:026c=0x00 x:026d=0x00 x:026e=0x00 x:026f=0x00
x:0270=0x00 x:0271=0x00 x:0272=0x00 x:0273=0x00 x:0274=0x00 x:0275=0x00 x:0276=0x00 x:0277=0x00
x:0278=0x00 x:0279=0x00 x:027a=0x00 x:027b=0x00 x:027c=0x00 x:027d=0x00 x:027e=0x00 x:027f=0x00
x:0280=0x00 x:0281=0x00 x:0282=0x00 x:0283=0x00 x:0284=0x00 x:0285=0x00 x:0286=0x00 x:0287=0x40
x:0288=0x00 x:0289=0x00 x:028a=0x00 x:028b=0x00 x:028c=0x00 x:028d=0x00 x:028e=0x00 x:028f=0x00
x:0290=0x00 x:0291=0x00 x:0292=0x00 x:0293=0x00 x:0294=0x00 x:0295=0x00 x:0296=0x00 x:0297=0x00
x:0298=0x00 x:0299=0x00 x:029a=0x00 x:029b=0x00 x:029c=0x00 x:029d=0x00 x:029e=0x00 x:029f=0x00
x:02a0=0x00 x:02a1=0x00 x:02a2=0x00 x:02a3=0x00 x:02a4=0x00 x:02a5=0x00 x:02a6=0x00 x:02a7=0x00
x:02a8=0x00 x:02a9=0x00 x:02aa=0x00 x:02ab=0x00 x:02ac=0x00 x:02ad=0x00 x:02ae=0x00 x:02af=0x00
x:02b0=0x00 x:02b1=0x00 x:02b2=0x00 x:02b3=0x00 x:02b4=0x00 x:02b5=0x00 x:02b6=0x00 x:02b7=0x00
x:02b8=0x00 x:02b9=0x00 x:02ba=0x00 x:02bb=0x00 x:02bc=0x00 x:02bd=0x00 x:02be=0x00 x:02bf=0x00
x:02c0=0x00 x:02c1=0x00 x:02c2=0x00 x:02c3=0x00 x:02c4=0x00 x:02c5=0x00 x:02c6=0x00 x:02c7=0x00
x:01c8=0x00 x:01c9=0x00 x:01ca=0x00 x:01cb=0x30 x:01cc=0x00 x:01cd=0x00 x:01ce=0x00 x:01cf=0x00
x:01d0=0x00 x:01d1=0x00 x:01d2=0x00 x:01d3=0x00 x:01d4=0x00 x:01d5=0x00 x:01d6=0x00 x:01d7=0x00
x:01d8=0x00 x:01d9=0x00 x:01da=0x00 x:01db=0x00 x:01dc=0x00 x:01dd=0x00 x:01de=0x00 x:01df=0x00
x:01e0=0x00 x:01e1=0x00 x:01e2=0x00 x:01e3=0x00 x:01e4=0x00 x:01e5=0x00 x:01e6=0x00 x:01e7=0x00
x:01e8=0x00 x:01e9=0x00 x:01ea=0x00 x:01eb=0x00 x:01ec=0x00 x:01ed=0x00 x:01ee=0x00 x:01ef=0x00
x:01f0=0x00 x:01f1=0x00 x:01f2=0x00 x:01f3=0x00 x:01f4=0x00 x:01f5=0x00 x:01f6=0x00 x:01f7=0x00
x:01f8=0x00 x:01f9=0x00 x:01fa=0x00 x:01fb=0x00 x:01fc=0x00 x:01fd=0x00 x:01fe=0x00 x:01ff=0xC8
x:0200=0x00 x:0201=0x00 x:0202=0x00 x:0203=0x00 x:0204=0x00 x:0205=0x00 x:0206=0x00 x:0207=0x00
x:0208=0x00 x:0209=0x00 x:020a=0x00 x:020b=0x00 x:020c=0x00 x:020d=0x00 x:020e=0x00 x:020f=0x00
x:0210=0x00 x:0211=0x00 x:0212=0x00 x:0213=0x00 x:0214=0x00 x:0215=0x00 x:0216=0x00 x:0217=0x00
x:0218=0x00 x:0219=0x00 x:021a=0x00 x:021b=0x00 x:021c=0x00 x:021d=0x00 x:021e=0x00 x:021f=0x00
x:0220=0x00 x:0221=0x00 x:0222=0x00 x:0223=0x00 x:0224=0x00 x:0225=0x00 x:0226=0x00 x:0227=0x00
x:0228=0x00 x:0229=0x00 x:022a=0x00 x:022b=0x00 x:022c=0x00 x:022d=0x00 x:022e=0x00 x:022f=0x00
x:0230=0x00 x:0231=0x00 x:0232=0x00 x:0233=0x00 x:0234=0x00 x:0235=0x00 x:0236=0x00 x:0237=0x00
x:0238=0x00 x:0239=0x00 x:023a=0x00 x:023b=0x00 x:023c=0x00 x:023d=0x00 x:023e=0x00 x:023f=0x00
x:0240=0x00 x:0241=0x00 x:0242=0x00 x:0243=0x00 x:0244=0x00 x:0245=0x00 x:0246=0x00 x:0247=0x00
x:0248=0x00 x:0249=0x00 x:024a=0x00 x:024b=0x00 x:024c=0x00 x:024d=0x00 x:024e=0x00 x:024f=0x00
x:0250=0x00 x:0251=0x00 x:0252=0x00 x:0253=0x00 x:0254=0x00 x:0255=0x00 x:0256=0x00 x:0257=0x00
x:0258=0x00 x:0259=0x00 x:025a=0x00 x:025b=0x00 x:025c=0x00 x:025d=0x00 x:025e=0x00 x:025f=0x00
x:0260=0x00 x:0261=0x00 x:0262=0x00 x:0263=0x00 x:0264=0x00 x:0265=0x00 x:0266=0x00 x:0267=0x00
x:0268=0x00 x:0269=0x00 x:026a=0x00 x:026b=0x00 x:026c=0x00 x:026d=0x00 x:026e=0x00 x:026f=0x00
x:0270=0x00 x:0271=0x00 x:0272=0x00 x:0273=0x00 x:0274=0x00 x:0275=0x00 x:0276=0x00 x:0277=0x00
x:0278=0x00 x:0279=0x00 x:027a=0x00 x:027b=0x00 x:027c=0x00 x:027d=0x00 x:027e=0x00 x:027f=0x00
x:0280=0x00 x:0281=0x00 x:0282=0x00 x:0283=0x00 x:0284=0x00 x:0285=0x00 x:0286=0x00 x:0287=0x40
x:0288=0x00 x:0289=0x00 x:028a=0x00 x:028b=0x00 x:028c=0x00 x:028d=0x00 x:028e=0x00 x:028f=0x00
x:0290=0x00 x:0291=0x00 x:0292=0x00 x:0293=0x00 x:0294=0x00 x:0295=0x00 x:0296=0x00 x:0297=0x00
x:0298=0x00 x:0299=0x00 x:029a=0x00 x:029b=0x00 x:029c=0x00 x:029d=0x00 x:029e=0x00 x:029f=0x00
x:02a0=0x00 x:02a1=0x00 x:02a2=0x00 x:02a3=0x00 x:02a4=0x00 x:02a5=0x00 x:02a6=0x00 x:02a7=0x00
x:02a8=0x00 x:02a9=0x00 x:02aa=0x00 x:02ab=0x00 x:02ac=0x00 x:02ad=0x00 x:02ae=0x00 x:02af=0x00
x:02b0=0x00 x:02b1=0x00 x:02b2=0x00 x:02b3=0x00 x:02b4=0x00 x:02b5=0x00 x:02b6=0x00 x:02b7=0x00
x:02b8=0x00 x:02b9=0x00 x:02ba=0x00 x:02bb=0x00 x:02bc=0x00 x:02bd=0x00 x:02be=0x00 x:02bf=0x00
x:02c0=0x00 x:02c1=0x00 x:02c2=0x00 x:02c3=0x00 x:02c4=0x00 x:02c5=0x00 x:02c6=0x00 x:02c7=0x00
可以看出,申请lp1后再释放掉lp1,可用的内存是又变成了0xFC,再次申请lp2时,又从0x02c7开始,并且剩余的数量 0x30也是对的;只是第一次申请的保存信息的四个字节的内容还保留着;
3.2 申请lp1(64),申请lp2(64),释放lp1,申请lp3(32字节),释放lp2
lp1 malloc ok
x:0288=0x00 x:0289=0x00 x:028a=0x00 x:028b=0x00 x:028c=0x00 x:028d=0x00 x:028e=0x00 x:028f=0x00
x:0290=0x00 x:0291=0x00 x:0292=0x00 x:0293=0x00 x:0294=0x00 x:0295=0x00 x:0296=0x00 x:0297=0x00
x:0298=0x00 x:0299=0x00 x:029a=0x00 x:029b=0x00 x:029c=0x00 x:029d=0x00 x:029e=0x00 x:029f=0x00
x:02a0=0x00 x:02a1=0x00 x:02a2=0x00 x:02a3=0x00 x:02a4=0x00 x:02a5=0x00 x:02a6=0x00 x:02a7=0x00
x:02a8=0x00 x:02a9=0x00 x:02aa=0x00 x:02ab=0x00 x:02ac=0x00 x:02ad=0x00 x:02ae=0x00 x:02af=0x00
x:02b0=0x00 x:02b1=0x00 x:02b2=0x00 x:02b3=0x00 x:02b4=0x00 x:02b5=0x00 x:02b6=0x00 x:02b7=0x00
x:02b8=0x00 x:02b9=0x00 x:02ba=0x00 x:02bb=0x00 x:02bc=0x00 x:02bd=0x00 x:02be=0x00 x:02bf=0x00
x:02c0=0x00 x:02c1=0x00 x:02c2=0x00 x:02c3=0x00 x:02c4=0x00 x:02c5=0x00 x:02c6=0x00 x:02c7=0x00
lp2 malloc ok
x:0244=0x00 x:0245=0x00 x:0246=0x00 x:0247=0x00 x:0248=0x00 x:0249=0x00 x:024a=0x00 x:024b=0x00
x:024c=0x00 x:024d=0x00 x:024e=0x00 x:024f=0x00 x:0250=0x00 x:0251=0x00 x:0252=0x00 x:0253=0x00
x:0254=0x00 x:0255=0x00 x:0256=0x00 x:0257=0x00 x:0258=0x00 x:0259=0x00 x:025a=0x00 x:025b=0x00
x:025c=0x00 x:025d=0x00 x:025e=0x00 x:025f=0x00 x:0260=0x00 x:0261=0x00 x:0262=0x00 x:0263=0x00
x:0264=0x00 x:0265=0x00 x:0266=0x00 x:0267=0x00 x:0268=0x00 x:0269=0x00 x:026a=0x00 x:026b=0x00
x:026c=0x00 x:026d=0x00 x:026e=0x00 x:026f=0x00 x:0270=0x00 x:0271=0x00 x:0272=0x00 x:0273=0x00
x:0274=0x00 x:0275=0x00 x:0276=0x00 x:0277=0x00 x:0278=0x00 x:0279=0x00 x:027a=0x00 x:027b=0x00
x:027c=0x00 x:027d=0x00 x:027e=0x00 x:027f=0x00 x:0280=0x00 x:0281=0x00 x:0282=0x00 x:0283=0x00
x:01c8=0x00 x:01c9=0x00 x:01ca=0x00 x:01cb=0x74 x:01cc=0x00 x:01cd=0x00 x:01ce=0x00 x:01cf=0x00
x:01d0=0x00 x:01d1=0x00 x:01d2=0x00 x:01d3=0x00 x:01d4=0x00 x:01d5=0x00 x:01d6=0x00 x:01d7=0x00
x:01d8=0x00 x:01d9=0x00 x:01da=0x00 x:01db=0x00 x:01dc=0x00 x:01dd=0x00 x:01de=0x00 x:01df=0x00
x:01e0=0x00 x:01e1=0x00 x:01e2=0x00 x:01e3=0x00 x:01e4=0x00 x:01e5=0x00 x:01e6=0x00 x:01e7=0x00
x:01e8=0x00 x:01e9=0x00 x:01ea=0x00 x:01eb=0x00 x:01ec=0x00 x:01ed=0x00 x:01ee=0x00 x:01ef=0x00
x:01f0=0x00 x:01f1=0x00 x:01f2=0x00 x:01f3=0x00 x:01f4=0x00 x:01f5=0x00 x:01f6=0x00 x:01f7=0x00
x:01f8=0x00 x:01f9=0x00 x:01fa=0x00 x:01fb=0x00 x:01fc=0x00 x:01fd=0x00 x:01fe=0x00 x:01ff=0x00
x:0200=0x00 x:0201=0x00 x:0202=0x00 x:0203=0x00 x:0204=0x00 x:0205=0x00 x:0206=0x00 x:0207=0x00
x:0208=0x00 x:0209=0x00 x:020a=0x00 x:020b=0x00 x:020c=0x00 x:020d=0x00 x:020e=0x00 x:020f=0x00
x:0210=0x00 x:0211=0x00 x:0212=0x00 x:0213=0x00 x:0214=0x00 x:0215=0x00 x:0216=0x00 x:0217=0x00
x:0218=0x00 x:0219=0x00 x:021a=0x00 x:021b=0x00 x:021c=0x00 x:021d=0x00 x:021e=0x00 x:021f=0x00
x:0220=0x00 x:0221=0x00 x:0222=0x00 x:0223=0x00 x:0224=0x00 x:0225=0x00 x:0226=0x00 x:0227=0x00
x:0228=0x00 x:0229=0x00 x:022a=0x00 x:022b=0x00 x:022c=0x00 x:022d=0x00 x:022e=0x00 x:022f=0x00
x:0230=0x00 x:0231=0x00 x:0232=0x00 x:0233=0x00 x:0234=0x00 x:0235=0x00 x:0236=0x00 x:0237=0x00
x:0238=0x00 x:0239=0x00 x:023a=0x00 x:023b=0x00 x:023c=0x00 x:023d=0x00 x:023e=0x00 x:023f=0x00
x:0240=0x00 x:0241=0x00 x:0242=0x00 x:0243=0x40 x:0244=0x00 x:0245=0x00 x:0246=0x00 x:0247=0x00
x:0248=0x00 x:0249=0x00 x:024a=0x00 x:024b=0x00 x:024c=0x00 x:024d=0x00 x:024e=0x00 x:024f=0x00
x:0250=0x00 x:0251=0x00 x:0252=0x00 x:0253=0x00 x:0254=0x00 x:0255=0x00 x:0256=0x00 x:0257=0x00
x:0258=0x00 x:0259=0x00 x:025a=0x00 x:025b=0x00 x:025c=0x00 x:025d=0x00 x:025e=0x00 x:025f=0x00
x:0260=0x00 x:0261=0x00 x:0262=0x00 x:0263=0x00 x:0264=0x00 x:0265=0x00 x:0266=0x00 x:0267=0x00
x:0268=0x00 x:0269=0x00 x:026a=0x00 x:026b=0x00 x:026c=0x00 x:026d=0x00 x:026e=0x00 x:026f=0x00
x:0270=0x00 x:0271=0x00 x:0272=0x00 x:0273=0x00 x:0274=0x00 x:0275=0x00 x:0276=0x00 x:0277=0x00
x:0278=0x00 x:0279=0x00 x:027a=0x00 x:027b=0x00 x:027c=0x00 x:027d=0x00 x:027e=0x00 x:027f=0x00
x:0280=0x00 x:0281=0x00 x:0282=0x00 x:0283=0x00 x:0284=0x00 x:0285=0x00 x:0286=0x00 x:0287=0x40
x:0288=0x00 x:0289=0x00 x:028a=0x00 x:028b=0x00 x:028c=0x00 x:028d=0x00 x:028e=0x00 x:028f=0x00
x:0290=0x00 x:0291=0x00 x:0292=0x00 x:0293=0x00 x:0294=0x00 x:0295=0x00 x:0296=0x00 x:0297=0x00
x:0298=0x00 x:0299=0x00 x:029a=0x00 x:029b=0x00 x:029c=0x00 x:029d=0x00 x:029e=0x00 x:029f=0x00
x:02a0=0x00 x:02a1=0x00 x:02a2=0x00 x:02a3=0x00 x:02a4=0x00 x:02a5=0x00 x:02a6=0x00 x:02a7=0x00
x:02a8=0x00 x:02a9=0x00 x:02aa=0x00 x:02ab=0x00 x:02ac=0x00 x:02ad=0x00 x:02ae=0x00 x:02af=0x00
x:02b0=0x00 x:02b1=0x00 x:02b2=0x00 x:02b3=0x00 x:02b4=0x00 x:02b5=0x00 x:02b6=0x00 x:02b7=0x00
x:02b8=0x00 x:02b9=0x00 x:02ba=0x00 x:02bb=0x00 x:02bc=0x00 x:02bd=0x00 x:02be=0x00 x:02bf=0x00
x:02c0=0x00 x:02c1=0x00 x:02c2=0x00 x:02c3=0x00 x:02c4=0x00 x:02c5=0x00 x:02c6=0x00 x:02c7=0x00
lp1 free ok
x:01c8=0x02 x:01c9=0x84 x:01ca=0x00 x:01cb=0x74 x:01cc=0x00 x:01cd=0x00 x:01ce=0x00 x:01cf=0x00
x:01d0=0x00 x:01d1=0x00 x:01d2=0x00 x:01d3=0x00 x:01d4=0x00 x:01d5=0x00 x:01d6=0x00 x:01d7=0x00
x:01d8=0x00 x:01d9=0x00 x:01da=0x00 x:01db=0x00 x:01dc=0x00 x:01dd=0x00 x:01de=0x00 x:01df=0x00
x:01e0=0x00 x:01e1=0x00 x:01e2=0x00 x:01e3=0x00 x:01e4=0x00 x:01e5=0x00 x:01e6=0x00 x:01e7=0x00
x:01e8=0x00 x:01e9=0x00 x:01ea=0x00 x:01eb=0x00 x:01ec=0x00 x:01ed=0x00 x:01ee=0x00 x:01ef=0x00
x:01f0=0x00 x:01f1=0x00 x:01f2=0x00 x:01f3=0x00 x:01f4=0x00 x:01f5=0x00 x:01f6=0x00 x:01f7=0x00
x:01f8=0x00 x:01f9=0x00 x:01fa=0x00 x:01fb=0x00 x:01fc=0x00 x:01fd=0x00 x:01fe=0x00 x:01ff=0x00
x:0200=0x00 x:0201=0x00 x:0202=0x00 x:0203=0x00 x:0204=0x00 x:0205=0x00 x:0206=0x00 x:0207=0x00
x:0208=0x00 x:0209=0x00 x:020a=0x00 x:020b=0x00 x:020c=0x00 x:020d=0x00 x:020e=0x00 x:020f=0x00
x:0210=0x00 x:0211=0x00 x:0212=0x00 x:0213=0x00 x:0214=0x00 x:0215=0x00 x:0216=0x00 x:0217=0x00
x:0218=0x00 x:0219=0x00 x:021a=0x00 x:021b=0x00 x:021c=0x00 x:021d=0x00 x:021e=0x00 x:021f=0x00
x:0220=0x00 x:0221=0x00 x:0222=0x00 x:0223=0x00 x:0224=0x00 x:0225=0x00 x:0226=0x00 x:0227=0x00
x:0228=0x00 x:0229=0x00 x:022a=0x00 x:022b=0x00 x:022c=0x00 x:022d=0x00 x:022e=0x00 x:022f=0x00
x:0230=0x00 x:0231=0x00 x:0232=0x00 x:0233=0x00 x:0234=0x00 x:0235=0x00 x:0236=0x00 x:0237=0x00
x:0238=0x00 x:0239=0x00 x:023a=0x00 x:023b=0x00 x:023c=0x00 x:023d=0x00 x:023e=0x00 x:023f=0x00
x:0240=0x00 x:0241=0x00 x:0242=0x00 x:0243=0x40 x:0244=0x00 x:0245=0x00 x:0246=0x00 x:0247=0x00
x:0248=0x00 x:0249=0x00 x:024a=0x00 x:024b=0x00 x:024c=0x00 x:024d=0x00 x:024e=0x00 x:024f=0x00
x:0250=0x00 x:0251=0x00 x:0252=0x00 x:0253=0x00 x:0254=0x00 x:0255=0x00 x:0256=0x00 x:0257=0x00
x:0258=0x00 x:0259=0x00 x:025a=0x00 x:025b=0x00 x:025c=0x00 x:025d=0x00 x:025e=0x00 x:025f=0x00
x:0260=0x00 x:0261=0x00 x:0262=0x00 x:0263=0x00 x:0264=0x00 x:0265=0x00 x:0266=0x00 x:0267=0x00
x:0268=0x00 x:0269=0x00 x:026a=0x00 x:026b=0x00 x:026c=0x00 x:026d=0x00 x:026e=0x00 x:026f=0x00
x:0270=0x00 x:0271=0x00 x:0272=0x00 x:0273=0x00 x:0274=0x00 x:0275=0x00 x:0276=0x00 x:0277=0x00
x:0278=0x00 x:0279=0x00 x:027a=0x00 x:027b=0x00 x:027c=0x00 x:027d=0x00 x:027e=0x00 x:027f=0x00
x:0280=0x00 x:0281=0x00 x:0282=0x00 x:0283=0x00 x:0284=0x00 x:0285=0x00 x:0286=0x00 x:0287=0x40
x:0288=0x00 x:0289=0x00 x:028a=0x00 x:028b=0x00 x:028c=0x00 x:028d=0x00 x:028e=0x00 x:028f=0x00
x:0290=0x00 x:0291=0x00 x:0292=0x00 x:0293=0x00 x:0294=0x00 x:0295=0x00 x:0296=0x00 x:0297=0x00
x:0298=0x00 x:0299=0x00 x:029a=0x00 x:029b=0x00 x:029c=0x00 x:029d=0x00 x:029e=0x00 x:029f=0x00
x:02a0=0x00 x:02a1=0x00 x:02a2=0x00 x:02a3=0x00 x:02a4=0x00 x:02a5=0x00 x:02a6=0x00 x:02a7=0x00
x:02a8=0x00 x:02a9=0x00 x:02aa=0x00 x:02ab=0x00 x:02ac=0x00 x:02ad=0x00 x:02ae=0x00 x:02af=0x00
x:02b0=0x00 x:02b1=0x00 x:02b2=0x00 x:02b3=0x00 x:02b4=0x00 x:02b5=0x00 x:02b6=0x00 x:02b7=0x00
x:02b8=0x00 x:02b9=0x00 x:02ba=0x00 x:02bb=0x00 x:02bc=0x00 x:02bd=0x00 x:02be=0x00 x:02bf=0x00
x:02c0=0x00 x:02c1=0x00 x:02c2=0x00 x:02c3=0x00 x:02c4=0x00 x:02c5=0x00 x:02c6=0x00 x:02c7=0x00
lp3 malloc ok
x:0220=0x00 x:0221=0x00 x:0222=0x00 x:0223=0x00 x:0224=0x00 x:0225=0x00 x:0226=0x00 x:0227=0x00
x:0228=0x00 x:0229=0x00 x:022a=0x00 x:022b=0x00 x:022c=0x00 x:022d=0x00 x:022e=0x00 x:022f=0x00
x:0230=0x00 x:0231=0x00 x:0232=0x00 x:0233=0x00 x:0234=0x00 x:0235=0x00 x:0236=0x00 x:0237=0x00
x:0238=0x00 x:0239=0x00 x:023a=0x00 x:023b=0x00 x:023c=0x00 x:023d=0x00 x:023e=0x00 x:023f=0x00
x:01c8=0x02 x:01c9=0x84 x:01ca=0x00 x:01cb=0x50 x:01cc=0x00 x:01cd=0x00 x:01ce=0x00 x:01cf=0x00
x:01d0=0x00 x:01d1=0x00 x:01d2=0x00 x:01d3=0x00 x:01d4=0x00 x:01d5=0x00 x:01d6=0x00 x:01d7=0x00
x:01d8=0x00 x:01d9=0x00 x:01da=0x00 x:01db=0x00 x:01dc=0x00 x:01dd=0x00 x:01de=0x00 x:01df=0x00
x:01e0=0x00 x:01e1=0x00 x:01e2=0x00 x:01e3=0x00 x:01e4=0x00 x:01e5=0x00 x:01e6=0x00 x:01e7=0x00
x:01e8=0x00 x:01e9=0x00 x:01ea=0x00 x:01eb=0x00 x:01ec=0x00 x:01ed=0x00 x:01ee=0x00 x:01ef=0x00
x:01f0=0x00 x:01f1=0x00 x:01f2=0x00 x:01f3=0x00 x:01f4=0x00 x:01f5=0x00 x:01f6=0x00 x:01f7=0x00
x:01f8=0x00 x:01f9=0x00 x:01fa=0x00 x:01fb=0x00 x:01fc=0x00 x:01fd=0x00 x:01fe=0x00 x:01ff=0x00
x:0200=0x00 x:0201=0x00 x:0202=0x00 x:0203=0x00 x:0204=0x00 x:0205=0x00 x:0206=0x00 x:0207=0x00
x:0208=0x00 x:0209=0x00 x:020a=0x00 x:020b=0x00 x:020c=0x00 x:020d=0x00 x:020e=0x00 x:020f=0x00
x:0210=0x00 x:0211=0x00 x:0212=0x00 x:0213=0x00 x:0214=0x00 x:0215=0x00 x:0216=0x00 x:0217=0x00
x:0218=0x00 x:0219=0x00 x:021a=0x00 x:021b=0x00 x:021c=0x00 x:021d=0x00 x:021e=0x00 x:021f=0x20
x:0220=0x00 x:0221=0x00 x:0222=0x00 x:0223=0x00 x:0224=0x00 x:0225=0x00 x:0226=0x00 x:0227=0x00
x:0228=0x00 x:0229=0x00 x:022a=0x00 x:022b=0x00 x:022c=0x00 x:022d=0x00 x:022e=0x00 x:022f=0x00
x:0230=0x00 x:0231=0x00 x:0232=0x00 x:0233=0x00 x:0234=0x00 x:0235=0x00 x:0236=0x00 x:0237=0x00
x:0238=0x00 x:0239=0x00 x:023a=0x00 x:023b=0x00 x:023c=0x00 x:023d=0x00 x:023e=0x00 x:023f=0x00
x:0240=0x00 x:0241=0x00 x:0242=0x00 x:0243=0x40 x:0244=0x00 x:0245=0x00 x:0246=0x00 x:0247=0x00
x:0248=0x00 x:0249=0x00 x:024a=0x00 x:024b=0x00 x:024c=0x00 x:024d=0x00 x:024e=0x00 x:024f=0x00
x:0250=0x00 x:0251=0x00 x:0252=0x00 x:0253=0x00 x:0254=0x00 x:0255=0x00 x:0256=0x00 x:0257=0x00
x:0258=0x00 x:0259=0x00 x:025a=0x00 x:025b=0x00 x:025c=0x00 x:025d=0x00 x:025e=0x00 x:025f=0x00
x:0260=0x00 x:0261=0x00 x:0262=0x00 x:0263=0x00 x:0264=0x00 x:0265=0x00 x:0266=0x00 x:0267=0x00
x:0268=0x00 x:0269=0x00 x:026a=0x00 x:026b=0x00 x:026c=0x00 x:026d=0x00 x:026e=0x00 x:026f=0x00
x:0270=0x00 x:0271=0x00 x:0272=0x00 x:0273=0x00 x:0274=0x00 x:0275=0x00 x:0276=0x00 x:0277=0x00
x:0278=0x00 x:0279=0x00 x:027a=0x00 x:027b=0x00 x:027c=0x00 x:027d=0x00 x:027e=0x00 x:027f=0x00
x:0280=0x00 x:0281=0x00 x:0282=0x00 x:0283=0x00 x:0284=0x00 x:0285=0x00 x:0286=0x00 x:0287=0x40
x:0288=0x00 x:0289=0x00 x:028a=0x00 x:028b=0x00 x:028c=0x00 x:028d=0x00 x:028e=0x00 x:028f=0x00
x:0290=0x00 x:0291=0x00 x:0292=0x00 x:0293=0x00 x:0294=0x00 x:0295=0x00 x:0296=0x00 x:0297=0x00
x:0298=0x00 x:0299=0x00 x:029a=0x00 x:029b=0x00 x:029c=0x00 x:029d=0x00 x:029e=0x00 x:029f=0x00
x:02a0=0x00 x:02a1=0x00 x:02a2=0x00 x:02a3=0x00 x:02a4=0x00 x:02a5=0x00 x:02a6=0x00 x:02a7=0x00
x:02a8=0x00 x:02a9=0x00 x:02aa=0x00 x:02ab=0x00 x:02ac=0x00 x:02ad=0x00 x:02ae=0x00 x:02af=0x00
x:02b0=0x00 x:02b1=0x00 x:02b2=0x00 x:02b3=0x00 x:02b4=0x00 x:02b5=0x00 x:02b6=0x00 x:02b7=0x00
x:02b8=0x00 x:02b9=0x00 x:02ba=0x00 x:02bb=0x00 x:02bc=0x00 x:02bd=0x00 x:02be=0x00 x:02bf=0x00
x:02c0=0x00 x:02c1=0x00 x:02c2=0x00 x:02c3=0x00 x:02c4=0x00 x:02c5=0x00 x:02c6=0x00 x:02c7=0x00
lp2 free ok
x:01c8=0x02 x:01c9=0x40 x:01ca=0x00 x:01cb=0x50 x:01cc=0x00 x:01cd=0x00 x:01ce=0x00 x:01cf=0x00
x:01d0=0x00 x:01d1=0x00 x:01d2=0x00 x:01d3=0x00 x:01d4=0x00 x:01d5=0x00 x:01d6=0x00 x:01d7=0x00
x:01d8=0x00 x:01d9=0x00 x:01da=0x00 x:01db=0x00 x:01dc=0x00 x:01dd=0x00 x:01de=0x00 x:01df=0x00
x:01e0=0x00 x:01e1=0x00 x:01e2=0x00 x:01e3=0x00 x:01e4=0x00 x:01e5=0x00 x:01e6=0x00 x:01e7=0x00
x:01e8=0x00 x:01e9=0x00 x:01ea=0x00 x:01eb=0x00 x:01ec=0x00 x:01ed=0x00 x:01ee=0x00 x:01ef=0x00
x:01f0=0x00 x:01f1=0x00 x:01f2=0x00 x:01f3=0x00 x:01f4=0x00 x:01f5=0x00 x:01f6=0x00 x:01f7=0x00
x:01f8=0x00 x:01f9=0x00 x:01fa=0x00 x:01fb=0x00 x:01fc=0x00 x:01fd=0x00 x:01fe=0x00 x:01ff=0x00
x:0200=0x00 x:0201=0x00 x:0202=0x00 x:0203=0x00 x:0204=0x00 x:0205=0x00 x:0206=0x00 x:0207=0x00
x:0208=0x00 x:0209=0x00 x:020a=0x00 x:020b=0x00 x:020c=0x00 x:020d=0x00 x:020e=0x00 x:020f=0x00
x:0210=0x00 x:0211=0x00 x:0212=0x00 x:0213=0x00 x:0214=0x00 x:0215=0x00 x:0216=0x00 x:0217=0x00
x:0218=0x00 x:0219=0x00 x:021a=0x00 x:021b=0x00 x:021c=0x00 x:021d=0x00 x:021e=0x00 x:021f=0x20
x:0220=0x00 x:0221=0x00 x:0222=0x00 x:0223=0x00 x:0224=0x00 x:0225=0x00 x:0226=0x00 x:0227=0x00
x:0228=0x00 x:0229=0x00 x:022a=0x00 x:022b=0x00 x:022c=0x00 x:022d=0x00 x:022e=0x00 x:022f=0x00
x:0230=0x00 x:0231=0x00 x:0232=0x00 x:0233=0x00 x:0234=0x00 x:0235=0x00 x:0236=0x00 x:0237=0x00
x:0238=0x00 x:0239=0x00 x:023a=0x00 x:023b=0x00 x:023c=0x00 x:023d=0x00 x:023e=0x00 x:023f=0x00
x:0240=0x00 x:0241=0x00 x:0242=0x00 x:0243=0x84 x:0244=0x00 x:0245=0x00 x:0246=0x00 x:0247=0x00
x:0248=0x00 x:0249=0x00 x:024a=0x00 x:024b=0x00 x:024c=0x00 x:024d=0x00 x:024e=0x00 x:024f=0x00
x:0250=0x00 x:0251=0x00 x:0252=0x00 x:0253=0x00 x:0254=0x00 x:0255=0x00 x:0256=0x00 x:0257=0x00
x:0258=0x00 x:0259=0x00 x:025a=0x00 x:025b=0x00 x:025c=0x00 x:025d=0x00 x:025e=0x00 x:025f=0x00
x:0260=0x00 x:0261=0x00 x:0262=0x00 x:0263=0x00 x:0264=0x00 x:0265=0x00 x:0266=0x00 x:0267=0x00
x:0268=0x00 x:0269=0x00 x:026a=0x00 x:026b=0x00 x:026c=0x00 x:026d=0x00 x:026e=0x00 x:026f=0x00
x:0270=0x00 x:0271=0x00 x:0272=0x00 x:0273=0x00 x:0274=0x00 x:0275=0x00 x:0276=0x00 x:0277=0x00
x:0278=0x00 x:0279=0x00 x:027a=0x00 x:027b=0x00 x:027c=0x00 x:027d=0x00 x:027e=0x00 x:027f=0x00
x:0280=0x00 x:0281=0x00 x:0282=0x00 x:0283=0x00 x:0284=0x00 x:0285=0x00 x:0286=0x00 x:0287=0x40
x:0288=0x00 x:0289=0x00 x:028a=0x00 x:028b=0x00 x:028c=0x00 x:028d=0x00 x:028e=0x00 x:028f=0x00
x:0290=0x00 x:0291=0x00 x:0292=0x00 x:0293=0x00 x:0294=0x00 x:0295=0x00 x:0296=0x00 x:0297=0x00
x:0298=0x00 x:0299=0x00 x:029a=0x00 x:029b=0x00 x:029c=0x00 x:029d=0x00 x:029e=0x00 x:029f=0x00
x:02a0=0x00 x:02a1=0x00 x:02a2=0x00 x:02a3=0x00 x:02a4=0x00 x:02a5=0x00 x:02a6=0x00 x:02a7=0x00
x:02a8=0x00 x:02a9=0x00 x:02aa=0x00 x:02ab=0x00 x:02ac=0x00 x:02ad=0x00 x:02ae=0x00 x:02af=0x00
x:02b0=0x00 x:02b1=0x00 x:02b2=0x00 x:02b3=0x00 x:02b4=0x00 x:02b5=0x00 x:02b6=0x00 x:02b7=0x00
x:02b8=0x00 x:02b9=0x00 x:02ba=0x00 x:02bb=0x00 x:02bc=0x00 x:02bd=0x00 x:02be=0x00 x:02bf=0x00
x:02c0=0x00 x:02c1=0x00 x:02c2=0x00 x:02c3=0x00 x:02c4=0x00 x:02c5=0x00 x:02c6=0x00 x:02c7=0x00
由于每次记录下输出很麻烦;我现在直接来说下我的结论;首先我们约定
使用 lp1 来指示 lp1 = malloc(64) 的首地址;是0x0284;而不是 lp1 = malloc(64) 的可用地址字节首 0x0288,使用lp1len表示其空间大小 64 + 4
lp1,lp2,lp3,lp4,lp5雷同
使用 len 表示这个数组可用的字符数,即上例中的地址0x01cb中的0x30;
使用addr来表示释放内存后 x:01c8=0x00 x:01c9=0x00 中的地址;
首先
我们注意到上一次的输出中,在free(lp1)后,addr保存了lp1的首地址;且len相对释放前并没有增大;
然后 lp3 = malloc(32);这时可以看出,申请到的内存是lp2之后的地址,而不是覆盖刚lp1释放后的地址;len减小相应的大小
然后在释放free(lp2);addr保存了lp2的首地址;且len相对释放前同样没有增大;
最后在释放 lp3,得到了最早的状态
结论:
我们申请了 lp1,lp2,lp3,lp4,lp5,之后,len = 252 -lp1len -lp2len - lp3len - lp4len -lp5len,addr = 0;
得到下面这表格
0x01c8 | addr | |
0x01cb | len | |
0x0214 | lp5 | lp5len |
0x0238 | lp4 | lp4len |
0x025c | lp3 | lp3len |
0x0280 | lp2 | lp2len |
0x02a4 | lp1 | lp1len |
malloc:每次调用该函数时,
假如中间没有 free时,总是接着上一个malloc的地址获取;len减小;
假如中间有free,假如不是释放上一次的malloc,len不变,addr指向最大free的lpn;就接着上一个malloc的地址获取,len减小;
假如是释放的上一个malloc,则len增大,addr指向0;就接着上一个的上一个malloc的地址获取,len减小;
总之:addr始终指向释放的n个lp中的最大的地址,假如最后一次malloc的内存没有释放的话;否则指向0,且len 增大到;
说不清楚,举几个例子,假如malloc lp1,lp2,lp3,lp4,lp5, len = 252 - lp1len - lp2len - lp3len - lp4len -lp5len,addr = 0
示例1:
free(lp4) len=len addr=lp4
free(lp3) len=len addr=lp4
free(lp5) len+=lp5len+lp4len+lp3len addr=0
free(lp2) len+=lp2len addr=0
free(lp1) len+=lp1len addr=0
示例2:
free(lp3) len=len addr=lp3
free(lp4) len=len addr=lp4
free(lp5) len+=lp5len+lp4len+lp3len addr=0
free(lp1) len=len addr=lp1
free(lp2) len+=lp1len+lp2len addr=0
示例3:
malloc(lp1) len-=lp1len addr=0
malloc(lp2) len-=lp2len addr=0
malloc(lp3) len-=lp3len addr=0
free(lp2) len=len addr=lp2
malloc(lp4) len-=lp4len addr=lp2
malloc(lp5) len-=lp5len addr=lp2
free(lp3) len=len addr=lp3
free(lp4) len=len addr=lp4
free(lp5) len=lp5len+lp4len+lp3len+lp2len addr=0
free(lp1) len+=lp1len addr=0
至此,都没有出现问题;
4 申请lp1(128),申请lp2(200)
输出如下
lp1 malloc ok
x:0248=0x00 x:0249=0x00 x:024a=0x00 x:024b=0x00 x:024c=0x00 x:024d=0x00 x:024e=0x00 x:024f=0x00
x:0250=0x00 x:0251=0x00 x:0252=0x00 x:0253=0x00 x:0254=0x00 x:0255=0x00 x:0256=0x00 x:0257=0x00
x:0258=0x00 x:0259=0x00 x:025a=0x00 x:025b=0x00 x:025c=0x00 x:025d=0x00 x:025e=0x00 x:025f=0x00
x:0260=0x00 x:0261=0x00 x:0262=0x00 x:0263=0x00 x:0264=0x00 x:0265=0x00 x:0266=0x00 x:0267=0x00
x:0268=0x00 x:0269=0x00 x:026a=0x00 x:026b=0x00 x:026c=0x00 x:026d=0x00 x:026e=0x00 x:026f=0x00
x:0270=0x00 x:0271=0x00 x:0272=0x00 x:0273=0x00 x:0274=0x00 x:0275=0x00 x:0276=0x00 x:0277=0x00
x:0278=0x00 x:0279=0x00 x:027a=0x00 x:027b=0x00 x:027c=0x00 x:027d=0x00 x:027e=0x00 x:027f=0x00
x:0280=0x00 x:0281=0x00 x:0282=0x00 x:0283=0x00 x:0284=0x00 x:0285=0x00 x:0286=0x00 x:0287=0x00
x:0288=0x00 x:0289=0x00 x:028a=0x00 x:028b=0x00 x:028c=0x00 x:028d=0x00 x:028e=0x00 x:028f=0x00
x:0290=0x00 x:0291=0x00 x:0292=0x00 x:0293=0x00 x:0294=0x00 x:0295=0x00 x:0296=0x00 x:0297=0x00
x:0298=0x00 x:0299=0x00 x:029a=0x00 x:029b=0x00 x:029c=0x00 x:029d=0x00 x:029e=0x00 x:029f=0x00
x:02a0=0x00 x:02a1=0x00 x:02a2=0x00 x:02a3=0x00 x:02a4=0x00 x:02a5=0x00 x:02a6=0x00 x:02a7=0x00
x:02a8=0x00 x:02a9=0x00 x:02aa=0x00 x:02ab=0x00 x:02ac=0x00 x:02ad=0x00 x:02ae=0x00 x:02af=0x00
x:02b0=0x00 x:02b1=0x00 x:02b2=0x00 x:02b3=0x00 x:02b4=0x00 x:02b5=0x00 x:02b6=0x00 x:02b7=0x00
x:02b8=0x00 x:02b9=0x00 x:02ba=0x00 x:02bb=0x00 x:02bc=0x00 x:02bd=0x00 x:02be=0x00 x:02bf=0x00
x:02c0=0x00 x:02c1=0x00 x:02c2=0x00 x:02c3=0x00 x:02c4=0x00 x:02c5=0x00 x:02c6=0x00 x:02c7=0x00
lp2 malloc ok
x:0000=0x00 x:0001=0x00 x:0002=0x03 x:0003=0x00 x:0004=0x00 x:0005=0x03 x:0006=0x00 x:0007=0x00
x:0008=0x03 x:0009=0x00 x:000a=0x00 x:000b=0x03 x:000c=0x00 x:000d=0x00 x:000e=0x00 x:000f=0x00
x:0010=0x00 x:0011=0x00 x:0012=0x00 x:0013=0x00 x:0014=0x00 x:0015=0x00 x:0016=0x00 x:0017=0x00
x:0018=0x00 x:0019=0x00 x:001a=0x00 x:001b=0x00 x:001c=0x00 x:001d=0x00 x:001e=0x00 x:001f=0x00
x:0020=0x00 x:0021=0x00 x:0022=0x00 x:0023=0x00 x:0024=0x00 x:0025=0x00 x:0026=0x00 x:0027=0x00
x:0028=0x00 x:0029=0x00 x:002a=0x00 x:002b=0x00 x:002c=0x00 x:002d=0x00 x:002e=0x00 x:002f=0x00
x:0030=0x00 x:0031=0x00 x:0032=0x00 x:0033=0x00 x:0034=0x00 x:0035=0x00 x:0036=0x00 x:0037=0x00
x:0038=0x00 x:0039=0x00 x:003a=0x00 x:003b=0x00 x:003c=0x00 x:003d=0x00 x:003e=0x00 x:003f=0x00
x:0040=0x00 x:0041=0x00 x:0042=0x00 x:0043=0x00 x:0044=0x00 x:0045=0x00 x:0046=0x00 x:0047=0x00
x:0048=0x00 x:0049=0x00 x:004a=0x00 x:004b=0x00 x:004c=0x00 x:004d=0x00 x:004e=0x00 x:004f=0x00
x:0050=0x00 x:0051=0x00 x:0052=0x00 x:0053=0x00 x:0054=0x00 x:0055=0x00 x:0056=0x00 x:0057=0x00
x:0058=0x00 x:0059=0x00 x:005a=0x00 x:005b=0x00 x:005c=0x00 x:005d=0x00 x:005e=0x00 x:005f=0x00
x:0060=0x00 x:0061=0x00 x:0062=0x00 x:0063=0x00 x:0064=0x00 x:0065=0x00 x:0066=0x00 x:0067=0x00
x:0068=0x00 x:0069=0x00 x:006a=0x00 x:006b=0x00 x:006c=0x00 x:006d=0x00 x:006e=0x00 x:006f=0x00
x:0070=0x00 x:0071=0x00 x:0072=0x00 x:0073=0x00 x:0074=0x00 x:0075=0x00 x:0076=0x00 x:0077=0x00
x:0078=0x00 x:0079=0x00 x:007a=0x00 x:007b=0x00 x:007c=0x00 x:007d=0x00 x:007e=0x00 x:007f=0x00
x:0080=0x00 x:0081=0x00 x:0082=0x00 x:0083=0x00 x:0084=0x00 x:0085=0x00 x:0086=0x00 x:0087=0x00
x:0088=0x00 x:0089=0x00 x:008a=0x00 x:008b=0x00 x:008c=0x00 x:008d=0x00 x:008e=0x00 x:008f=0x00
x:0090=0x00 x:0091=0x00 x:0092=0x00 x:0093=0x00 x:0094=0x00 x:0095=0x00 x:0096=0x00 x:0097=0x00
x:0098=0x00 x:0099=0x00 x:009a=0x00 x:009b=0x00 x:009c=0x00 x:009d=0x00 x:009e=0x00 x:009f=0x00
x:00a0=0x00 x:00a1=0x00 x:00a2=0x00 x:00a3=0x00 x:00a4=0x00 x:00a5=0x00 x:00a6=0x00 x:00a7=0x00
x:00a8=0x00 x:00a9=0x00 x:00aa=0x00 x:00ab=0x00 x:00ac=0x00 x:00ad=0x00 x:00ae=0x00 x:00af=0x00
x:00b0=0x00 x:00b1=0x00 x:00b2=0x00 x:00b3=0x00 x:00b4=0x00 x:00b5=0x00 x:00b6=0x00 x:00b7=0x00
x:00b8=0x00 x:00b9=0x00 x:00ba=0x00 x:00bb=0x00 x:00bc=0x00 x:00bd=0x00 x:00be=0x00 x:00bf=0x00
x:00c0=0x00 x:00c1=0x00 x:00c2=0x00 x:00c3=0x00 x:00c4=0x00 x:00c5=0x00 x:00c6=0x00 x:00c7=0x00
地址都出现了问题,但是malloc没有返回NULL;
所以,好像还有C51的动态分配还有问题;但是是否每次都读取len的长度,在申请不超出len的长度,是否可以正常使用malloc,free等动态分配函数呢?