[ Bottom of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]

Technical Reference: Base Operating System and Extensions, Volume 1

brk or sbrk Subroutine


Changes data segment space allocation.


Standard C Library (libc.a)


#include <unistd .h>

int brk ( EndDataSegment)
char *EndDataSegment;

void *sbrk ( Increment)
intptr_t Increment;


The brk and sbrk subroutines dynamically change the amount of space allocated for the data segment of the calling process. (For information about segments, see the exec subroutine. For information about the maximum amount of space that can be allocated, see the ulimit and getrlimit subroutines.)

The change is made by resetting the break value of the process, which determines the maximum space that can be allocated. The break value is the address of the first location beyond the current end of the data region. The amount of available space increases as the break value increases. The available space is initialized to a value of 0 at the time it is used. The break value can be automatically rounded up to a size appropriate for the memory management architecture.

The brk subroutine sets the break value to the value of the EndDataSegment parameter and changes the amount of available space accordingly.

The sbrk subroutine adds to the break value the number of bytes contained in the Increment parameter and changes the amount of available space accordingly. The Increment parameter can be a negative number, in which case the amount of available space is decreased.


EndDataSegment Specifies the effective address of the maximum available data.
Increment Specifies any integer.

Return Values

Upon successful completion, the brk subroutine returns a value of 0, and the sbrk subroutine returns the old break value. If either subroutine is unsuccessful, a value of -1 is returned and the errno global variable is set to indicate the error.

Error Codes

The brk subroutine and the sbrk subroutine are unsuccessful and the allocated space remains unchanged if one or more of the following are true:

ENOMEM The requested change allocates more space than is allowed by a system-imposed maximum. (For information on the system-imposed maximum on memory space, see the ulimit system call.)
ENOMEM The requested change sets the break value to a value greater than or equal to the start address of any attached shared-memory segment. (For information on shared memory operations, see the shmat subroutine.)

Related Information

The exec (exec: execl, execle, execlp, execv, execve, execvp, or exect Subroutine) subroutines, getrlimit (getrlimit, getrlimit64, setrlimit, setrlimit64, or vlimit Subroutine) subroutine, shmat subroutine, shmdt subroutine, ulimit subroutine.

The _end (_end, _etext, or _edata Identifier), _etext (_end, _etext, or _edata Identifier), or _edata (_end, _etext, or _edata Identifier) identifier.

Subroutine Overview in AIX 5L Version 5.2 General Programming Concepts: Writing and Debugging Programs.

[ Top of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]