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>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   <alloc.h>                    Required for declarations only

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

    sbrk() adjusts the size of a program's allocated memory by adding
    'incr' bytes to the break value of the calling process.  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 successful; -1 if an error
                    occurred.  If -1 is returned, 'errno' (defined in
                    <errno.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'.


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

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

           #include <alloc.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' */
               }
           }


See Also: malloc() coreleft()

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