Digital Signal Processing LibraryVoice LabProgram name: matrix_allocate Language: C In file: vector_lib.c Objective: Allocate memory for a list of vectors Usage: void matrix_allocate(double ***matrix, double **matrix_data_ptr, int vector_width, int number_vectors_max); Parameters:
Mathematical Description: Comments: Routine is used to allocate memory for a list of vectors Code: void matrix_allocate(double ***matrix, double **matrix_data_ptr, int vector_width, int *number_vectors_max) { int i; /* allocate space for reading in the vectors */ (*matrix_data_ptr) = malloc((*number_vectors_max) * vector_width * sizeof(double)); if((*matrix_data_ptr) == NULL) { fprintf(stderr, "Cannot allocate memory for data\n"); exit(1); } /* allocate space for pointers to the vectors */ *matrix = malloc((*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); } } |
English Version > Documents and tutorials > D.Sc. projects > Routines for DSP > vector_lib >