Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Borland C++ 2.x ( with Turbo C ) - <b>brk() change data-segment space allocation</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 brk()                   Change Data-Segment Space Allocation

 #include   <alloc.h>

 int        brk(endds);
 void       *endds;                      New ending address

    brk() changes the space allocated to the data segment of a calling
    program by resetting the program's 'break value'--the address of the
    first location past the end of the data segment.  brk() sets the
    'break value' to 'endds'.  As the break value increases, so does the
    amount of allocated space.

       Returns:     0, if successful.  If the function fails, -1 is
                    returned and 'errno' (defined in <errno.h>) is set to
                    ENOMEM, not enough memory.

         Notes:     If an attempt is made to allocate more space than is
                    allowed, brk() fails and the space allocated to the
                    data segment remains unchanged.

   -------------------------------- Example ---------------------------------

           #include <alloc.h>      /* for brk and sbrk */
           #include <stdio.h>      /* for printf */

           main()
           {
               char *start;

               start = sbrk(5000); /* allocates 5000 bytes
                                        & returns old break value */
               if (start == (char*)-1)
                   printf("Not enough memory\n");
               else  {             /* allocates 2000 more bytes */
                   if (sbrk(2000) == (char*)-1)
                       printf("Not enough memory\n");
                   brk(start);     /*deallocates both blocks */
               }
           }


See Also: coreleft() sbrk()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson