RE: A question about TClonesArray

From: Datao Gong <dtgong_at_physics.umn.edu>
Date: Thu, 10 Nov 2005 11:40:40 -0600 (CST)


Yes, I just browsed the source code. It is true. Thank you and Rene.

Datao

On Thu, 10 Nov 2005, Philippe Canal wrote:

>
>> theData->Clear(); //Clear the TClonesArray, Does this mean the orignal
>
> This simply tell the TClonesArray that it is empty (however it kepts holding
> the memory it has allocated so far for later reuse.
>
>> //AddrAt(Int_t) just return the Object* in specified slot, so it
>> //does nothing here?
>
> No. It actually set the entry as valid (if it was not already) and
> should (if it is the first time) use:
> new (theData->AddrAt(entry)) MyClass(...);
> to properly initizalize it.
>
> Cheers,
> Philippe.
>
> -----Original Message-----
> From: owner-roottalk_at_pcroot.cern.ch [mailto:owner-roottalk_at_pcroot.cern.ch]
> On Behalf Of Datao Gong
> Sent: Thursday, November 10, 2005 10:32 AM
> Cc: roottalk_at_pcroot.cern.ch
> Subject: [ROOT] A question about TClonesArray
>
> Hi, Guys,
> When i read a piece of code writte by other people, i think i might
> misunderstand something about TClonesArray.
>
> This code increase TClonesArray size on demand. It should not change the
> content which has been filled in.
>
> My question are embeded in the comments.
>
> if(theMaxSize < 10) theMaxSize = 10;
> else if(theMaxSize < 30) theMaxSize = 30;
> else if(theMaxSize < 100) theMaxSize = 100;
> else if(theMaxSize < 250) theMaxSize = 250;
> else theMaxSize *= 2;
>
> theData->ExpandCreateFast(theMaxSize); //increase Size
>
> theData->Clear(); //Clear the TClonesArray, Does this mean the orignal
> //infomation are lost after that!?
>
> for(Int_t entry = 0; entry < theSize; ++entry) theData->AddrAt(entry);
> //AddrAt(Int_t) just return the Object* in specified slot, so it
> //does nothing here?
>
> BTW, this code works. But i just do not know why.
>
> Thanks,
>
> Datao
>
>
>
Received on Thu Nov 10 2005 - 18:40:48 MET

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:13 MET