help-gsl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-gsl] Help with GSL Matrices


From: adarsh
Subject: Re: [Help-gsl] Help with GSL Matrices
Date: Sun, 11 Jun 2006 18:21:26 -0500 (CDT)
User-agent: SquirrelMail/1.4.5

Thanks everyone. All those emails help.


> 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 mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/help-gsl
>






reply via email to

[Prev in Thread] Current Thread [Next in Thread]