matrix_allocate

Digital Signal Processing Library

Voice Lab

Program 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:

  • matrix - The pointer to the array of vectors (a matrix)
  • matrix_data_ptr - Pointer to the actual data - Auxiliary pointer
  • vector_width - Number of elements in each vector
  • number_vectors_max - array allocated for this amount

Mathematical Description:

Comments: Routine is used to allocate memory for a list of vectors

User Comments

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);
        }
}