home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume8 / graph+ / part03 / new.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-03-01  |  822 b   |  51 lines

  1. /*
  2.  * Copyright (C) 1986   Alan Kent
  3.  *
  4.  * Permission is granted to freely distribute part or
  5.  * all of this code as long as it is not for profit
  6.  * and this message is retained in the code.
  7.  *
  8.  * No resposibility is taken for any damage or incorect
  9.  * results this program generates.
  10.  * 
  11.  */
  12.  
  13.  
  14. #include <stdio.h>
  15.  
  16.  
  17. extern char *malloc ();
  18.  
  19. int bytes_allocated = 0;
  20.  
  21.  
  22. char *
  23. new ( size )
  24. int size;
  25. {
  26.     char *p;
  27.     char buf[100];
  28.  
  29.     if ( size < 1 )
  30.     size = 1;
  31.     p = malloc ( size );
  32.     if ( p == NULL ) {
  33.     sprintf ( buf ,
  34.         "out of memory: request for %d bytes failed, %d allocated so far\n",
  35.         size , bytes_allocated );
  36.     abort ( buf );
  37.     }
  38.     bytes_allocated += size;
  39.     return ( p );
  40. }
  41.  
  42.  
  43. release ( mem )
  44. char *mem;
  45. {
  46.     if ( mem == NULL )
  47.     abort ( "Trying to free NULL pointer" );
  48.     free ( mem );
  49. }
  50.  
  51.