Skip to content
Snippets Groups Projects
Commit c2038667 authored by Philippe Canal's avatar Philippe Canal
Browse files

From ideas provided by Mike Marino, introduce TClonesArray::ConstructedAt which

always returns an already constructed object.   If the slot is being used for the
first time, it calls the default constructor otherwise it returns the object as 
is (unless a string is passed as the 2nd argument to the function in which case,
it also calls Clear(second_argument) on the object).
This allows replace code like:
   for (int i = 0; i < ev->Ntracks; i++) {
       new(a[i]) TTrack(x,y,z,...);
       ...
       ...
   }
   ...
   a.Delete(); // or a.Clear("C")
with the simpler and more efficient:
   for (int i = 0; i < ev->Ntracks; i++) {   
       TTrack *track = (TTrack*)a.ConstructedAt(i);
       track->Set(x,y,z,....);
       ...                                                          
       ...                                                          
   }                                                               
   ...                                                             
   a.Clear();
even in case where the TTrack class allocates memory.


git-svn-id: http://root.cern.ch/svn/root/trunk@40562 27541ba8-7e3a-0410-8455-c3a389f83636
parent c2ce7b1c
No related branches found
No related tags found
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment