#include "stdio.h"
#include "stddef.h"
void main (int argc,char *argv[])
{
void *p=sbrk(0);//the top of the heap
int *p1=(int *)p;
brk(p1+4);//change the heap size,allocate 4*4 bytes to the heap
printf("malloc %d byte!\n",sbrk(0)-(int)p);
p=sbrk(0);
brk(p+100); //allocate 100 bytes to the heap
printf("malloc %d byte!\n",sbrk(0)-(int)p);
void *p2=sbrk(0);
brk(p+50);//release 100-50 bytes to the heap
printf("allocate %d byte!\n",sbrk(0)-(int)p2);
}
阅读(1573) | 评论(0) | 转发(0) |