brk()

NAME

brk(), sbrk() - set or change space allocation

SYNOPSIS

#include <unistd.h>

int brk (void *addr) void * sbrk (int incr)

DESCRIPTION

The brk(3) and sbrk(3) functions change the amount of space allocated for the calling process. They change the space by resetting the break value for the process; as the break value increases, so does the allocated space. Initially, a newly-allocated space is set to 0.

The brk(3) function sets the break value to addr and sets the allocated space accordingly.

The sbrk(3) function increases the break value by incr bytes, and adjusts the allocated space. If incr, the function decreases the break value by the appropriate amount. if the value of incr is 0, then the function returns the current value of the break point.

The interaction of brk(3) and sbrk(3) with other memory functions is uncertain. Be careful, since other function calls may be call functions such as free(3) or mmap(2) in a non-obvious way.

The brk(3) and sbrk(3) functions are often used as atomic units to build other memory allocation functions. Application programmers should consider whether mmap(2) could be used, because it is more portable with other memory allocation functions.

RETURN VALUE

The brk(3) call returns 0 if it completes successfully. Otherwise it returns -1 and sets errno to indicate the error.

ERRORS

The brk(3) and sbrk(3) functions can fail for the following reasons:

[EAGAIN]
There is insufficient system memory available for the allocation. This condition might occur even if the allocation is less than the maximum data segment size, and it may be a temporary occurrence.
[ENOMEM]
The change will allocate more space than allowed, or the change is impossible for some reasons (perhaps thereis not sufficient swap space or the change would cause a memory allocation conflict).

SEE ALSO

exec(2)

mmap(2)

malloc(3)