home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume21 / rayshade / part01 / src / memory.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-03-21  |  1.6 KB  |  71 lines

  1. /*
  2.  * memory.c
  3.  *
  4.  * Copyright (C) 1989, Craig E. Kolb
  5.  *
  6.  * This software may be freely copied, modified, and redistributed,
  7.  * provided that this copyright notice is preserved on all copies.
  8.  *
  9.  * There is no warranty or other guarantee of fitness for this software,
  10.  * it is provided solely .  Bug reports or fixes may be sent
  11.  * to the author, who may or may not act on them as he desires.
  12.  *
  13.  * You may not include this software in a program or other software product
  14.  * without supplying the source, or without informing the end-user that the
  15.  * source is available for no extra charge.
  16.  *
  17.  * If you modify this software, you should include a notice giving the
  18.  * name of the person performing the modification, the date of modification,
  19.  * and the reason for such modification.
  20.  *
  21.  * $Id: memory.c,v 3.0 89/10/27 02:05:56 craig Exp $
  22.  *
  23.  * $Log:    memory.c,v $
  24.  * Revision 3.0  89/10/27  02:05:56  craig
  25.  * Baseline for first official release.
  26.  * 
  27.  */
  28. #include <stdio.h>
  29. #include "typedefs.h"
  30. #include "funcdefs.h"
  31.  
  32. unsigned long TotalAllocated;
  33.  
  34. char *
  35. Malloc(bytes)
  36. unsigned bytes;
  37. {
  38.     char *res, *malloc();
  39.  
  40.     TotalAllocated += bytes;
  41.  
  42.     res = malloc(bytes);
  43.     if (res == (char *)0) {
  44.         fprintf(stderr,"Out of memory trying to allocate %d bytes.\n");
  45.         exit(0);
  46.     }
  47.     return res;
  48. }
  49.  
  50. char *
  51. Calloc(nelem, elen)
  52. unsigned nelem, elen;
  53. {
  54.     char *res;
  55.  
  56.     res = Malloc(nelem*elen);
  57. #ifdef SYSV
  58.     memset(res, (char)0, nelem*elen);
  59. #else
  60.     bzero(res, nelem*elen);
  61. #endif
  62.     return res;
  63. }
  64.  
  65. PrintMemoryStats()
  66. {
  67.     extern FILE *fstats;
  68.  
  69.     fprintf(fstats,"Total memory allocated:\t\t%d bytes\n",TotalAllocated);
  70. }
  71.