calloc2f, free2f, - dynamic allocators for two dimensional arrays of floats
float **calloc2f(size_t jmax, size_t imax);
void free2f(float **d);
These allocators create two dimensional arrays of float values.
calloc2f allocates a two dimensional array of float values dimensioned jmax by imax. If the return value is assigned to d, then the highest index of the array is d[jmax-1][imax-1]. d[0] is a contiguous block of jmax * imax float values.
The dimension array in d is terminated with a pointer to the end of the value array. In other words, d[jmax] points to d[jmax-1][imax]. Also d[jmax+1] is NULL. This facilitates array traversal with minimal indexing. The follow- ing loops are equivalent.
for (j = 0; j < jmax; j++)
for (i = 0; i < imax; i++)
use(dat[j][i]);
for (p2 = dat; p2[1]; p2++)
for (p = p2[0]; p < p2[1]; p++)
use(*p);
The second loop might be faster for some compilers and options.
If something goes wrong, the function generates an error message that can be retrieved with a call to err_get, and returns NULL.
free2f frees all memory associated with d, which should be a return value of calloc2f.
alloc3f (3), alloc4f (3), err_msg (3), allocfvi (1).
Gordon Carrie (dev0 at this site)