dynamic allocation (arrayalloc) update

sources-request at genrad.UUCP sources-request at genrad.UUCP
Thu Aug 15 20:14:16 AEST 1985


Mod.sources:  Volume 2, Issue 36
Submitted by: decvax!mcnc!idis!george (George Rosenberg)

I added a call to free in arrayalloc so that memory would not be lost.

I also wrote a header file, "alloc2.h", with some macros to make a better
interface to the package.  Usage should be obvious.  Note that in this
implementation of the macro FREE2D, three of the four arguments are ignored.
These were included both for uniformity and to allow for other implementations.
Other implementations may also want to provide for dimensions of type long.
Use of the macros would simplify this.

	George Rosenberg

	duke!mcnc!idis!george
	decvax!idis!george



*** new:arrayalloc.c	Wed Aug 14 10:02:48 1985
--- old:arrayalloc.c	Wed Aug 14 09:32:53 1985
***************
*** 49,56
  	/*
  	 * Get memory for intermediate row address vector.
  	 */
! 	if ((vector = (char **) malloc (imax * sizeof (char *))) == NULL) {
! 		free(array) ;
  		return (NULL);
- 	}
  

--- 49,55 -----
  	/*
  	 * Get memory for intermediate row address vector.
  	 */
! 	if ((vector = (char **) malloc (imax * sizeof (char *))) == NULL)
  		return (NULL);
  
  	/*




----
Below is the contents of file "alloc2.h".
----
extern char **arrayalloc() ;
extern void arrayfree() ;

#define	ALLOC2D(type,dim0,dim1) \
	(type**)arrayalloc((unsigned)dim0,(unsigned)dim1,(unsigned)sizeof(type))
#define	FREE2D(type,addr,dim0,dim1) arrayfree((char**)addr)
----



More information about the Mod.sources mailing list