Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C 6.0 - <b>sbrk() reset break value for calling process</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 sbrk()                  Reset Break Value for Calling Process

 #include   <malloc.h>                   Required for declarations only

 void       *sbrk(incr);
 int        incr;                        Number of bytes to add or subtract

    sbrk() adds 'incr' bytes to the break value of the calling process
    and thus alters the size of the memory allocated to the program.  The
    break value is the address of the first byte of unallocated memory;
    if 'incr' is negative, the amount of allocated space is reduced.

    Returns:    The old break value, if succesful.  On error,(char *) -1
                is returned and 'errno' (defined in <stdlib.h>) is set to
                ENOMEM (defined in <errno.h>), indicating that
                insufficient memory was available.  This error can occur
                for both positive and negative values of 'incr'.

      Notes:    Be forewarned that sbrk() fails (returns (char *) -1) in
                compact, large, and huge model programs.  Use malloc()
                for allocation requests in programs with more than one
                data segment.

 Portability:   Does not support ANSI standard.

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

    The following statements allocate 200 bytes and then reduce the
    allocated memory to 80 bytes:

           #include <malloc.h>
           #include <stdio.h>      /* for printf */

           char *memptr;

           main()
           {
               if ((memptr = sbrk(200)) == (char *) -1)
                   printf("not enough room to allocate memory\n");
               else {
                   .
                   .
                   sbrk(-120);  /* don't reset 'memptr' */
               }
           }



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