Re: [ROOT] TArrayD

From: Fons Rademakers (Fons.Rademakers@cern.ch)
Date: Fri Mar 28 2003 - 18:29:50 MET


The fact that you can do this does not mean that it should work. Why
would you like to do this, instead of using the dtor? For these simple
classes all data members are public for easy access, but you should not
do silly things. You can also pass a 0 to strlen and get a segv.

-- Fons


On Fri, 2003-03-28 at 16:41, Brett Viren wrote:
> GENTIT Francois-Xavier  DAPNIA writes:
>  > Dear Rooters,
>  > 
>  > The following 2 lines of code cause a crash of ROOT when compiled (not in
>  > CINT) :
>  > 
>  >  
>  > 
>  >   TArrayD *a = new TArrayD(10);
>  > 
>  >   delete [] a->fArray;
>  > 
>  >  
>  > 
>  > I have tried them on Linux RedHat with ROOT 3.05.02 and
>  > 
>  > On Windows XP, Visual C++.NET, ROOT 3.05.03
>  > 
>  >  
>  > 
>  > Both cases crash. fArray being public, it should work? Is it a bug or a
>  > feature?
> 
> Having it public is bad, imo.  But anyways, if you are going to delete
> it this you had probably do what TArrayD does internally:
> 
>    TArrayD *a = new TArrayD(10);
>  
>    delete [] a->fArray;
>    a->fArray = 0;
> 
> Or, looking at the implementation you could replace those last two
> lines with:
> 
>    a->Adopt(0,0);
> 
> 
> -Brett.
-- 
Org:    CERN, European Laboratory for Particle Physics.
Mail:   1211 Geneve 23, Switzerland
E-Mail: Fons.Rademakers@cern.ch              Phone: +41 22 7679248
WWW:    http://root.cern.ch/~rdm/            Fax:   +41 22 7679480



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:10 MET