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

  1. /* HALLOC.C illustrates dynamic allocation of huge memory using functions:
  2.  *      halloc          hfree
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <malloc.h>
  7. #include <stdlib.h>
  8.  
  9. main()
  10. {
  11.     char huge *bigbuf, huge *p;
  12.     long count = 100000L;
  13.  
  14.     /* Allocate huge buffer. */
  15.     bigbuf = (char huge *)halloc( count, sizeof( char ) );
  16.     if( bigbuf == NULL )
  17.     {
  18.         printf( "Insufficient memory" );
  19.         exit( 1 );
  20.     }
  21.  
  22.     /* Fill the buffer with characters. */
  23.     for( p = bigbuf; count; count--, p++ )
  24.         *p = (char)(count % 10) + '0';
  25.  
  26.     /* Free huge buffer. */
  27.     hfree( bigbuf );
  28.     exit( 0 );
  29. }
  30.