Chinaunix首页 | 论坛 | 博客
  • 博客访问: 74982
  • 博文数量: 13
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 164
  • 用 户 组: 普通用户
  • 注册时间: 2013-03-06 22:57
文章存档

2013年(13)

我的朋友

分类: C/C++

2013-04-21 15:34:14

#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);
}
阅读(1554) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~