Next: , Previous: , Up: Top   [Contents][Index]


24 The "calib/new.h" Header.

The "calib/new.h" header contains the following macros and functions that make allocating memory much friendly and more type-safe:

	#define CALIB_NEW(T)	((T *) _calib_new (sizeof (T)))

	#define CALIB_NEWA(N,T)	((T *) _calib_new ((N) * sizeof (T)))

	#define CALIB_FREE(p) \
		do { if ((p) NE NULL) { free ((void *) (p)); } } while (FALSE)

	extern void *	_calib_new (size_t nbytes);

CALIB_NEW(T) dynamically allocates a single (uninitialized) object of type T. CALIB_NEWA(N, T) dynamically allocates an array (uninitialized) of N objects of type T. CALIB_FREE(p) checks for NULL before calling free(). The _calib_new function catches the out-of-memory condition (by printing an error message and calling exit(1)).