home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
vis-ftp.cs.umass.edu
/
vis-ftp.cs.umass.edu.tar
/
vis-ftp.cs.umass.edu
/
pub
/
Software
/
ASCENDER
/
ascendMar8.tar
/
UMass
/
Triangulate
/
include
/
alloc.h
next >
Wrap
C/C++ Source or Header
|
1995-04-13
|
2KB
|
73 lines
/* @(#)alloc.h 1.11 12/21/94 */
/* Macros for allocating and freeing matrices and vectors */
#ifndef alloc_h
#define alloc_h
#include "rh_util.h"
#ifdef SUN4
#include <alloca.h>
#endif
#ifndef __cplusplus
# define ALLOCA(len) \
(((zztchar=(char *)alloca((unsigned)len))==0)? \
(fprintf(stderr,"ERROR ***Out of space.***\n"),(char *)bail_out(1)) \
:zztchar)
/* Allocate temporary matrix and vector storage on the stack */
# define TVECTOR(nl, nh, type) \
(type *) (ALLOCA(((nh)-(nl)+1)*sizeof(type)) - (nl)*sizeof(type))
# define TMATRIX(xl,xh,yl,yh,type) \
(type **) alloca_matrix ((xl), (xh), (yl), (yh), sizeof(type), \
(char **)ALLOCA(((xh)-(xl)+1)*(sizeof(char *) + \
((yh)-(yl)+1) * sizeof(type))))
#endif
/* Allocate storage on the heap */
#define VECTOR(nl, nh, type) \
(type *) (MALLOC(((nh)-(nl)+1)*sizeof(type)) - (nl)*sizeof(type))
/* Allocate storage on the heap */
#define MATRIX(xl,xh,yl,yh,type) \
(type **) malloc_matrix ((xl), (xh), (yl), (yh), sizeof(type))
#define FREE(m,nrl) \
{ \
if (m) free((char *)((m)+(nrl))); \
m = NULL; \
}
#define SUBMATRIX(A,xl,yl,xdim,ydim,orgx,orgy,type) \
(type **) submatrix (A, xl, yl, xdim, orgx, orgy, sizeof(type))
#define ARRAY(n,p) VECTOR (0, (n)-1, p)
/*--------------------------------------------------------------------
* These macros should be used instead of VECTOR and FREE, when
* we mant to make vectors of class members.
* The difference is that in C++ we will call the empty constructor
* methods for vectors of class members, such as VECTOR (1, 3, Vector).
*-------------------------------------------------------------------*/
#ifdef __cplusplus
# define GVECTOR(nl, nh, type) ((new type [(nh)-(nl)+1]) - (nl))
# define GVFREE(m,nrl) delete [] ((m) + (nrl))
#else
/* Included just in case we use this with ordinary data types in a c program */
# define GVECTOR(nl, nh, type) VECTOR(nl, nh, type)
# define GVFREE(m,nrl) FREE(m,nrl)
#endif
#endif