NAME
SYNOPSIS
#include "alloc3f.h"
DESCRIPTION
SEE ALSO
AUTHOR

NAME

calloc3f, freef3, - dynamic allocators for three dimensional arrays of floats

SYNOPSIS

#include "alloc3f.h"

float ***calloc3f(size_t kmax, size_t jmax, size_t imax);
void freef3(float ***d);

DESCRIPTION

These allocators create three dimensional arrays of float values.

calloc3f allocates a three dimensional array of float values. If the return value is assigned to d, then the highest index of the array is d[kmax-1][jmax-1][imax-1]. d[0][0] is a contiguous block of kmax * jmax * imax floats.

Each dimension array in d is terminated with a pointer to the end of the next dimension. In other words, d[kmax] points to d[kmax-1][jmax], and d[kmax-1][jmax] points to d[kmax-1][jmax-1][imax]. Also, d[kmax+1] is NULL. This facilitates array traversal with minimal indexing. The following loops are equivalent.

for (k = 0; k < kmax; k++)
for (j = 0; j < jmax; j++)
for (i = 0; i < imax; i++)
use(dat[k][j][i]);

for (p3 = dat; p3[1]; p3++)
for (p2 = p3[0]; p2 < p3[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.

freef3 frees all memory associated with d, which should be a return value of malloc3f.

SEE ALSO

alloc2f (3), alloc4f (3), err_msg (3), allocfvi (1).

AUTHOR

Gordon Carrie (dev0 at this site)