brk
Changes data-segment space allocation.
Defined in header <alloc.h>
Syntax
#include <alloc.h>
int brk(void *addr);
Portability
| DOS | UNIX | Windows | ANSI C | C++ only |
|---|---|---|---|---|
| ■ | ■ |
Remarks
brk dynamically changes the amount of space allocated to the calling program's heap. The change is made by resetting the program's break value, which 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.
brk sets the break value to addr and changes the allocated space accordingly.
This function will fail without making any change in the allocated space if such a change would allocate more space than is allowable.
Return value
Upon successful completion, brk returns a value of 0. On failure, this function returns a value of -1 and the global variable errno is set to
| ENOMEM | Not enough memory |
See also
Example
#include <stdio.h>
#include <alloc.h>
int main(void)
{
char *ptr;
printf("Changing allocation with brk()\n");
ptr = (char *) malloc(l) ;
printf("Before brk() call: %lu bytes free\n", coreleft I
brk(ptr+1000);
printf(" After brk() call: %lu bytes free\n", coreleft I
return 0;
Differences from modern implementations
Nothing recorded yet.
Modern references
These are search links, not yet checked by hand.
Stable link: /3.1/alloc.h/brk/
· short form /3.1/brk/