utl_malloc
[ XITE Reference Manual | XITE home ]
Contents
Name
utl_malloc, Mmatrix_3d, Fmatrix_3d, Mmatrix_2d, Fmatrix_2d,
Mmatrix_1d, Fmatrix_1d - allocates memory for various purposes
#include <xite/utl_malloc.h>
void *Mmatrix_1d( int i_first, int i_last,
int i_element_size, int i_clear );
void *Mmatrix_2d( int i_row_min, int i_row_max,
int i_col_min, int i_col_max,
int i_element_size, int i_clear );
void *Mmatrix_3d( int i_x_min, int i_x_max,
int i_y_min, int i_y_max, int i_z_min,
int i_z_max, int i_element_size,
int i_clear );
void *Fmatrix_1d( char* array );
void *Fmatrix_2d( char* i_matrix,
char* i_rows );
void *Fmatrix_3d( char* i_cube, char* i_matrix,
char* i_rows );
These are various memory (de)allocation routines, all of them
using malloc (or calloc). element_size is the size of the elements to
be allocated; i.e sizeof(int) for integers. clear is one if the
array or matrix is to be filled by zeroes.
Mmatrix_1d returns a pointer to an array of (last - start + 1) elements.
After the call
a = Mmatrix_1d(1,4,sizeof(int),1)
a[1] will be the first integer element of the array, a[4] will be the
last. All elements will be initialized to 0.
Mmatrix_2d will return a pointer to a two-dimensional
rectangular matrix allocated
in one chunk of memory. row_start and row_last indicates first and last
element of the rows.
Mmatrix_3d will return a pointer to a three-dimensional rectangular cube
allocated in one chunk of memory. x_start, x_last, y_start, y_last,
z_start and z_last gives the dimension of the cube.
Fmatrix_1d frees the memory allocated by Mmatrix_1d. The adress of the
first dataelement must be supplied.
Fmatrix_2d frees the memory a||ocated by Mmatrix_2d. Parameters
are adress of first matrix element, and adress of first row. See
the example section for usage.
Fmatrix_3d frees the memory allocated by Mmatrix_3d. Parameters are adress
of first cube element, adress of first matrix element, and adress of first
row.
A suitable pointer is returned. If no storage
was available, or if routine deallocates memory, returns NULL.
All Fmatrix routines return NULL.
double **a;
Allocte room for a [0..2][0..8] double
precision matrix
a = Mmatrix_2d(0,2,0,8,sizeof(double),1);
Free a.
a = Fmatrix_2d( &a[0][0], &a[0]);
cc progname.c -lutl
Assumes all pointers have the same size (ok on decstations
and suns).
Always use row_start and col_start = 0: It will save you problems in
the long run. If you insist on offsets, remember to use
-
array[row_start, col_start] if the address of the first element is needed.
Compilers and lint might complain about mixing of data-types. Just
ignore them.
gutorm hogasen, NCC
malloc(3), free(3), calloc(3)
Last update 7/1/91
$Id: utl_malloc.c,v 1.16 1995/08/23 14:58:49 svein Exp $