Saturday, June 26, 2010

matrix_reallocate

Digital Signal Processing Library

Voice Lab

matrix_reallocate


void matrix_reallocate(double ***matrix, double **matrix_data_ptr, int vector_width, int *number_vectors_max)
{
int i;

/* increase maximum number of vectors permitted */
(*number_vectors_max) += ADDITIONAL_QUANTITY;

/* reallocate space for reading in the additional vectors */
(*matrix_data_ptr) = realloc((*matrix_data_ptr), (*number_vectors_max) * vector_width * sizeof(double));
if((*matrix_data_ptr) == NULL) {
fprintf(stderr, "Cannot allocate memory for data\n");
exit(1);
}

/* reallocate space for pointers to the additional vectors */
*matrix = realloc(*matrix, (*number_vectors_max) * sizeof(double *));
if(*matrix == NULL) {
fprintf(stderr, "Cannot allocate memory for data\n");
exit(1);
}

/* set pointers to point to array of data */
for(i = 0; i < (*number_vectors_max); i++) {
(*matrix)[i] = (*matrix_data_ptr) + (i * vector_width);
}
}



No comments:

Post a Comment