您的位置:首页 > 其它

sbrk 和brk 函数使用举例

2014-04-03 00:47 260 查看
#include <stdio.h>
#include <unistd.h>
int main(){
int *p1,*p2,*p3,*p4,*p5,*p6;
p1 = (int *)sbrk(sizeof(int));//Rxxx ---- ---- ----
*p1 = 1;
printf("%d\n",*p1);
printf("%p\n",p1);
p2 = (int *)sbrk(sizeof(int));//xxxx Rxxx ---- ----
*p2 = 2;
printf("%p\n",p2);
p3 = (int *)sbrk(sizeof(int));//xxxx xxxx Rxxx ----
*p3 = 3;
printf("%p\n",p3);
p4 = (int *)sbrk(-sizeof(int));//xxxx xxxx ---- R---
printf("%p\n",p4);
brk(p5 = p3 + 1);  //xxxx xxxx xxxx Rxxx
*p5 = 5;
printf("%p\n",p5);
brk(p1);                 //---- ---- ---- ---- R---
return 0;
}



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息