Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ brk(2) — Reliant UNIX 5.44c4

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

exec(2)

mmap(2)

malloc(3C)

unistd(4)

brk(2)                                                               brk(2)

NAME
     brk, sbrk - change data segment space allocation

SYNOPSIS
     #include <unistd.h>

     int brk(void *endds);

     void *sbrk(int incr);

DESCRIPTION
     brk() and sbrk() are used to change dynamically the amount of memory
     space allocated for the calling process' data segment [see exec(2)].
     The change is made by resetting the process' break value and allocat-
     ing the appropriate amount of memory space. The break value is the
     address of the first location beyond the end of the data segment. The
     amount of allocated memory space increases as the break value
     increases. Newly allocated memory 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
     space accordingly. incr can be negative, in which case the amount of
     allocated memory space is decreased.

ERRORS
     The following error code descriptions are function-specific. You will
     find a general description in introprm2(2) or in errno(5).

     The brk() and sbrk() functions will fail if:

     ENOMEM    The requested change would allocate more space than allowed.

     The brk() and sbrk() functions may fail if:

     EAGAIN    The total amount of system memory available for allocation
               to this process is temporarily insufficient. This may occur
               even though the space requested was less than the maximum
               data segment size.

     ENOMEM    The requested change would be impossible as there is insuf-
               ficient swap space available, or would cause a memory allo-
               cation conflict.

RETURN VALUE
     Upon successful completion, brk() returns 0. Otherwise, it returns -1
     and sets errno to indicate the error.





Page 1                       Reliant UNIX 5.44                Printed 11/98

brk(2)                                                               brk(2)

     Upon successful completion, sbrk() returns the prior break value. Oth-
     erwise, it returns (void *)-1 and sets errno to indicate the error.

APPLICATION USAGE
     The brk() and sbrk() functions have been used in specialized cases
     where no other memory allocation function provided the same capabil-
     ity. The use of mmap() is now preferred because it can be used port-
     ably with all other memory allocation functions and with any function
     that uses other allocation functions.

     It is unspecified whether the pointer returned by sbrk() is aligned
     suitably for any purpose.

SEE ALSO
     exec(2), mmap(2), malloc(3C), unistd(4).







































Page 2                       Reliant UNIX 5.44                Printed 11/98

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026