Re: [ROOT] A simple question about TClonesArray

From: Fons Rademakers (Fons.Rademakers@cern.ch)
Date: Tue Mar 05 2002 - 18:43:13 MET


Hi Pasha,

  TClonesArray reuses memory when you allocate your object via the new
with placement in the location the TClonesArray specifies. This memory
is reused in the next "iteration" or "event" because a Clear() or
Delete() does not delete the memory in which the objects are stored. The
pre-allocation can be done because the clonesarray knows exactly which
type of objects to expect and therefore can pre-allocate a bunch of
sizeof(myclass) size memory buffers. A clonesarray is most efficient
when myclass does not allocate any indirect memory (e.g. strings). In
that case the object fits completely in sizeof(myclass) and we don't
have to call the myclass::~myclass to recuperate the indirectly
allocated memory.

Splitting is done by introspection of myclass using the ROOT meta
(TClass) classes. Clonesarrays can be split since we know that all
objects are of the same type. Which is not the case for e.g. TObjArrays
which can contain any TObject derived object. Note, that a
vector<myclass> also can be split like a clonesarray but the default
vector<> lacks the optimized memory re-use scheme. One could propably
design a special "clonesallocator" for vector<> that would allow the
reuse of the vector<> memory.

Cheers, Fons.



On Tue, 2002-03-05 at 17:25, Pasha Murat wrote:
> On Tue, 05 Mar 2002 09:42:07 -0600
> "Philippe Canal" <pcanal@fnal.gov> wrote:
> 
> > Hi,
> > 
> > In a TClonesArray, you can (in recent version of ROOT) put objects of
> > the same class (which inherit directly or indirectly from TObject), but
> > the object can be of different 'size' (where the difference is actually
> > in the indirect memory foot-print).
> > 
> >
> There is a couple of non-obvious (at least for me) issues here:
> 
> - how memory is being reused and 
> - how splitting is done 
> 
> in case objects of the same class stored in TClonesArray have different sizes.
> Wondering if it is documented - didn't find anything in  TClonesArray section
> of 3.02a user guide.
> 
> 					best, Pasha
-- 
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 : Sat Jan 04 2003 - 23:50:44 MET