Linux Driver

2016年8月1日 星期一

brk, sbrk - change data segment size

brk, sbrk - change data segment size

brk and sbrk are basic memory management system calls used in Unix and Unix-like operating systems to control the amount of memory allocated to the data segment of the process.[1] 
These functions are typically called from a higher-level memory management library function such as malloc.
In the original Unix system, brk and sbrk were the only ways in which applications could acquire additional data space; later versions allowed this to also be done using the mmap call.

Function signatures and behavior

#include <unistd.h>

int brk(void *addr);

void *sbrk(intptr_t increment);

brk() and sbrk() change the location of the program break, which defines the end of the process's data segment (i.e., the program break is the first location after the end of the uninitialized data segment). Increasing the program break has the effect of allocating memory to the process; decreasing the break deallocates memory.

brk() sets the end of the data segment to the value specified by addr, when that value is reasonable, the system has enough memory, and the process does not exceed its maximum data size (see setrlimit(2)).

sbrk() increments the program's data space byincrement bytes. Calling sbrk() with an increment of 0 can be used to find the current location of the program break.

沒有留言 :