[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-gsl] Help with GSL Matrices
From: |
John D Lamb |
Subject: |
Re: [Help-gsl] Help with GSL Matrices |
Date: |
Sun, 11 Jun 2006 08:16:59 +0100 |
User-agent: |
Thunderbird 1.5 (X11/20060317) |
address@hidden wrote:
> Hey All:
>
> Is there a way we can avoid Segmentation fault error when we try to free a
> gsl_matrix that was never allocated, or that has already been freed?
>
If you don't allocate the matrix b when you declare it, try using
gsl_matrix b = 0;
Then you can free it using
if( b != 0 ){
gsl_matrix_free( b );
b = 0;
}
without worrying about whether b was allocated or already freed. This is
a standard technique and useful when you have conditional blocks of code
that may or may not allocate or free the matrix. If you want some
debugging information you can add an else to the delete block:
else {
// print some message about b not being allocated.
}
There are three likely reasons for gsl_matrix_free failing. First, you
may have bugs in your code. In that case you might try printing a
message whenever b is allocated or deleted or running a debugger that
traces what happens to b. Second, you may have b allocated
conditionally. The code above deals with this. Third, gsl_matrix_alloc
or gsl_matrix_free could fail for reasons not related to the first two.
Exceptions are only really designed to handle the third case.
--
JDL
- [Help-gsl] Help with GSL Matrices, adarsh, 2006/06/10
- Message not available
- Re: [Help-gsl] Help with GSL Matrices,
John D Lamb <=
- Re: [Help-gsl] Help with GSL Matrices, Jochen Küpper, 2006/06/11
- Re: [Help-gsl] Help with GSL Matrices, John D Lamb, 2006/06/11
- free (was: [Help-gsl] Help with GSL Matrices), Jochen Küpper, 2006/06/11
- [Help-gsl] Re: free, John D Lamb, 2006/06/11
- [Help-gsl] Re: free, Jochen Küpper, 2006/06/11
- [Help-gsl] Re: free, Brian Gough, 2006/06/12
- Re: [Help-gsl] Re: free, John D Lamb, 2006/06/12
- Re: [Help-gsl] Re: free, Jochen Küpper, 2006/06/12
- Re: [Help-gsl] Re: free, Brian Gough, 2006/06/14
Re: [Help-gsl] Help with GSL Matrices, adarsh, 2006/06/11