Changes data-segment space allocation
Declaration:
int brk(void *addr);
Remarks:
brk dynamically changes the amount of space allocated to the
calling
program's heap by resetting the program's break value to
addr.
brk and sbrk will fail without making any change in the allocated
space if
such a change would allocate more space than is allowable.
Return Value:
On success,
brk returns 0
On error, both functions return -1 and
set errno to
ENOMEM (not enough memory).
Program
#include <stdio.h>
#include <alloc.h>
int main(void)
{
char *ptr;
printf("Changing allocation with brk()\n");
ptr = (char *)
malloc(1);
printf("Before
brk() call: %lu bytes free\n", coreleft());
brk(ptr+1000);
printf(" After
brk() call: %lu bytes free\n", coreleft());
return 0;
}
0 comments:
Post a Comment