> brk ~ Online tutorial

brk


Brk
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;
}

Please Give Us Your 1 Minute In Sharing This Post!
Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Powered By: BloggerYard.Com

0 comments: