home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / c / other / memory / sbrk.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-25  |  785 b   |  33 lines

  1. /* SBRK.C illustrates memory allocation with function:
  2.  *      sbrk
  3.  */
  4.  
  5. #include <malloc.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8.  
  9. main()
  10. {
  11.     char *bufA, *bufB, *bufC;
  12.  
  13.     /* Allocate 512 bytes. */
  14.     if( (bufA = sbrk( 512 )) == (char *)-1 )
  15.         exit( 1 );
  16.     printf( "Allocate:\t256\tLocation:\t%p\n", (int far *)bufA );
  17.  
  18.     /* Allocate 50 bytes. */
  19.     if( (bufB = sbrk( 50 )) == (char *)-1 )
  20.         exit( 1 );
  21.     printf( "Allocate:\t50\tLocation:\t%p\n", (int far *)bufB );
  22.  
  23.     /* Deallocate 256 bytes. */
  24.     sbrk( -256 );
  25.     printf( "Deallocate:\t256\n" );
  26.  
  27.     /* Allocate 20 bytes. */
  28.     if( (bufC = sbrk( 20 )) == (char *)-1 )
  29.         exit( 1 );
  30.     printf( "Allocate:\t20\tLocation:\t%p\n", (int far *)bufC );
  31.     exit( 0 );
  32. }
  33.