brk, sbrk --
change data segment space allocation
int brk(void endds);
void sbrk(int incr);
brk and sbrk are used to change dynamically the amount of
space allocated for the calling process's data segment [see
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.
brk sets the break value to endds
and changes the allocated space accordingly.
sbrk adds incr bytes to the break value and changes the allocated
incr can be negative, in which case the amount of allocated space
On success, brk returns 0 and sbrk returns the old break value.
On failure, brk and sbrk return -1 and set errno
to identify the error without making any change in the allocated space.
In the following conditions, brk and sbrk fail and set errno to:
Such a change would result in more space being allocated
than is allowed by the system-imposed maximum process size [see
Total amount of system memory or swap space available is temporarily
This may occur even though the space requested was less than
the system-imposed maximum process size [see
Applications generally cope with the details of dynamic memory
allocation/deallocation by using the
Moreover, use of brk or sbrk can interfere with the
dynamic memory used by
Considerations for threads programming
Threads within a process share (by definition) the same address space;
modifications to the address space by one thread can
be perceived by sibling threads.
The sbrk function is actually a front end to the brk system call
and has a potential race condition that might produce incorrect results
if used concurrently by sibling threads. Such usage is not advised.
family of functions has been made safe for use by threads.
© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 - 01 June 2005