sbrk()                   Reset Break Value for Calling Process
 
 #include   <malloc.h>                   Required for declarations only
 
 char       *sbrk(incr);
 int        incr;                        Number of bytes to add or subtract
 
    sbrk() adds 'incr' bytes to the break value of the calling process.
    The break value is the address of the first byte of unallocated
    memory.  Changing the break value adjusts the size of the program's
    allocated memory.  If 'incr' is negative, the amount of allocated
    space is reduced.
 
    Returns:    The old break value,  or -1 if an error occurred.  If -1
                is returned, '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:    Important: In compact-, large- and huge-model programs,
                sbrk() fails and returns -1.  Use malloc() for allocation
                requests in programs with more than one data segment.
 
  -------------------------------- 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' */
                }
            }

Seealso:



This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster