[ADMB Users] The slow destruction of ADMB

Johnoel Ancheta johnoel at hawaii.edu
Sun Jan 1 10:13:39 PST 2012


Hmm, traced to revision 798 on old repository.  Will correct tommorrow.

On 1/1/12 6:17 AM, dave fournier wrote:
> I was getting strange behaviour (canadian spelling)  from a
> routine. I traced it to a buggy routine in  ivsort.cpp  which seems to 
> have
> replaced my original code.
>
>
>    int *intarray;
>    intarray = new int[size];
>    int i;
>    for(i=0;i<size;i++)
>    {
>       intarray[i] = v(lb+i);
>    }
>
>    //  .......
>
>    delete intarray;
>
> What is wrong with that?
>
> Two things. If you allocate memory with new int[size]
> you need to deallocate it with
>
>    delete [] intarray;
>
> Second you should not do this anyway. New and delete are really error 
> prone
> so you should use an ivector so that the destructor gets called 
> automatically.
>
>
>    ivector intarray(0,size-1);
>    int i;
>    for(i=0;i<size;i++)
>    {
>       intarray[i] = v(lb+i);
>    }
>
> Now you get bounds checking in the safe version of the code.
>
> Whenever you make a change to the code you should run it through 
> valgrind.
> With much more of this all of admb will be buggy and waste ones time with
> strange failures.
>
>
>
>
> _______________________________________________
> Users mailing list
> Users at admb-project.org
> http://lists.admb-project.org/mailman/listinfo/users
>




More information about the Users mailing list