home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume2 / runtime2 < prev    next >
Internet Message Format  |  1986-11-30  |  2KB

  1. From: decvax!mcnc!idis!george (George Rosenberg)
  2. Subject: dynamic allocation (arrayalloc) update
  3. Newsgroups: mod.sources
  4. Approved: john@genrad.UUCP
  5.  
  6. Mod.sources:  Volume 2, Issue 36
  7. Submitted by: decvax!mcnc!idis!george (George Rosenberg)
  8.  
  9. I added a call to free in arrayalloc so that memory would not be lost.
  10.  
  11. I also wrote a header file, "alloc2.h", with some macros to make a better
  12. interface to the package.  Usage should be obvious.  Note that in this
  13. implementation of the macro FREE2D, three of the four arguments are ignored.
  14. These were included both for uniformity and to allow for other implementations.
  15. Other implementations may also want to provide for dimensions of type long.
  16. Use of the macros would simplify this.
  17.  
  18.     George Rosenberg
  19.  
  20.     duke!mcnc!idis!george
  21.     decvax!idis!george
  22.  
  23.  
  24.  
  25. *** new:arrayalloc.c    Wed Aug 14 10:02:48 1985
  26. --- old:arrayalloc.c    Wed Aug 14 09:32:53 1985
  27. ***************
  28. *** 49,56
  29.       /*
  30.        * Get memory for intermediate row address vector.
  31.        */
  32. !     if ((vector = (char **) malloc (imax * sizeof (char *))) == NULL) {
  33. !         free(array) ;
  34.           return (NULL);
  35. -     }
  36.   
  37.  
  38. --- 49,55 -----
  39.       /*
  40.        * Get memory for intermediate row address vector.
  41.        */
  42. !     if ((vector = (char **) malloc (imax * sizeof (char *))) == NULL)
  43.           return (NULL);
  44.   
  45.       /*
  46.  
  47.  
  48.  
  49.  
  50. ----
  51. Below is the contents of file "alloc2.h".
  52. ----
  53. extern char **arrayalloc() ;
  54. extern void arrayfree() ;
  55.  
  56. #define    ALLOC2D(type,dim0,dim1) \
  57.     (type**)arrayalloc((unsigned)dim0,(unsigned)dim1,(unsigned)sizeof(type))
  58. #define    FREE2D(type,addr,dim0,dim1) arrayfree((char**)addr)
  59. ----
  60.  
  61.