home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / macraysh.sit / Code / Source / memory.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-07  |  1.4 KB  |  79 lines

  1. /*
  2.  * memory.c
  3.  *
  4.  * Copyright (C) 1989, 1991, Craig E. Kolb
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  * $Id: memory.c,v 4.0 91/07/17 14:30:57 kolb Exp Locker: kolb $
  17.  *
  18.  * $Log:    memory.c,v $
  19.  * Revision 4.0  91/07/17  14:30:57  kolb
  20.  * Initial version.
  21.  * 
  22.  */
  23.  
  24. #include "common.h"
  25.  
  26. unsigned long TotalAllocated;
  27.  
  28. voidstar
  29. Malloc(bytes)
  30. unsigned bytes;
  31. {
  32.     voidstar res;
  33.  
  34.     TotalAllocated += bytes;
  35.  
  36.     res = (voidstar)malloc(bytes);
  37.     if (res == (voidstar)NULL)
  38.         RLerror(RL_PANIC,
  39.             "Out of memory trying to allocate %d bytes.\n",(char *)bytes,0,0);
  40.     return res;
  41. }
  42.  
  43. voidstar
  44. Calloc(nelem, elen)
  45. unsigned nelem, elen;
  46. {
  47.     voidstar res;
  48.  
  49.     res = Malloc(nelem*elen);
  50.     bzero(res, (int)nelem*elen);
  51.     return res;
  52. }
  53.  
  54. void
  55. PrintMemoryStats(fp)
  56. FILE *fp;
  57. {
  58.     fprintf(fp,"Total memory allocated:\t\t%lu bytes\n",
  59.             TotalAllocated);
  60. }
  61.  
  62. /*
  63.  * Allocate space for a string, copy string into space.
  64.  */
  65. char *
  66. strsave(s)
  67. char *s;
  68. {
  69.     char *tmp;
  70.  
  71.     if (s == (char *)NULL)
  72.         return (char *)NULL;
  73.  
  74.     tmp = (char *)Malloc((unsigned)strlen(s) + 1);
  75.     (void)strcpy(tmp, s);
  76.     return tmp;
  77. }
  78.  
  79.