Removing memory leaks in C ++ and GNU science library code

double a[] = { 0.11, 0.12, 0.13,
                  0.21, 0.22, 0.23 };

   double b[] = { 1011, 1012,
                  1021, 1022,
                  1031, 1032 };

   double c[] = { 0.00, 0.00,
                  0.00, 0.00 };

   gsl_matrix_view A = gsl_matrix_view_array(a, 2, 3);
   gsl_matrix_view B = gsl_matrix_view_array(b, 3, 2);
   gsl_matrix_view C = gsl_matrix_view_array(c, 2, 2);

   /* Compute C = A B */

   gsl_blas_dgemm (CblasNoTrans, CblasNoTrans,
                   1.0, &A.matrix, &B.matrix,
                   0.0, &C.matrix);

How to free memory assigned to matrices?

+3
source share
1 answer

The compiler will take care of these matrices. If you do not use malloc()/new[]or any function that uses malloc()/new[]and gives you ownership of the allocated memory, there is no chance of a memory leak.

gsl_matrix_view_array() - , , , - . , malloc()/new , . malloc()/new[] ( , ) - free()/delete[] , .

+2

Source: https://habr.com/ru/post/1776867/


All Articles