#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;
}
sbrk 和brk 函数使用举例
最新推荐文章于 2023-11-28 17:46:27 发布