#include "matrix.h" matrix get_matrix_space(int m, int n) { int i; elem * p; matrix a; p = gmalloc(m * n * sizeof(elem)); /* get space all at once */ a = gmalloc(m * sizeof(row)); --a; /* offset the pointer */ for (i = 1; i <= m; ++i) a[i] = p + ((i - 1) * n) - 1; return a; } void release_matrix_space(matrix a) { elem * p; p = (elem *) a[1] + 1; /* base address of the array */ free(p); free(a + 1); }