Index of Section 3 Manual Pages
| Interix / SUA | sbrk.3 | Interix / SUA |
sbrk(3) sbrk(3)
brk()
NAME
brk(), sbrk() - set or change space allocation
SYNOPSIS
#include
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 is negative, 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 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.
The sbrk(3) call returns the previous value of the break point if it
completes successfully. Otherwise it returns (void *)-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)
USAGE NOTES
All of these functions are thread safe.
None of these functions are async-signal safe.