複製鏈接
請複製以下鏈接發送給好友

sbrk

鎖定
sbrk一種函數,能夠修改程序BSS段的大小。
中文名
sbrk
性    質
函數名
功 能
修改程序BSS段大小
用 法
char *sbrk(int incr)
頭文件:unistd.h
函數原型:void* sbrk(intptr_t incr)
作用:將內核的brk指針增加incr來擴展和收縮堆。
返回值:
函數調用成功則返回舊的brk指針。
函數調用失敗則返回(void*)-1,將errno設為ENOMEM。
程序例:
#include <stdio.h>
#include <alloc.h>
int main(void)
{
printf("Changing allocation with sbrk()\n");
printf("Before sbrk() call: %lu bytes free\n",
(unsigned long) coreleft());
sbrk(1000);
printf(" After sbrk() call: %lu bytes free\n",
(unsigned long) coreleft());
return 0;
}