The brk() and sbrk() functions are used to change dynamically the amount of space allocated for the calling process's data segment (see exec(2)). The change is made by resetting the process's break value and allocating the appropriate amount of space. The break value
is the address of the first location beyond the end of the data segment. The amount of allocated space increases as the break value increases. Newly allocated space is set to zero. If, however, the same
memory space is reallocated to the same process its contents are undefined.
When a program begins execution using execve() the break is set at the highest location defined by the program and data storage areas.
The getrlimit(2) function may be used to determine the maximum permissible size
of the data segment; it is not possible to set the break beyond the rlim_max value returned from a call to getrlimit(), that is to say, "end + rlim.rlim_max." See end(3C).
The brk() function sets the break value to endds and changes the allocated space accordingly.
The sbrk() function adds incr function bytes to the break value and changes the allocated space accordingly. The incr function can
be negative, in which case the amount of allocated space is decreased.
|