Re: [ROOT] memory allocation in default constructor

From: Rene Brun (Rene.Brun@cern.ch)
Date: Tue May 22 2001 - 17:48:44 MEST


Hi Silvie,

It is good practice to not allocate memory in the default constructor.
You should correctly initialize pointers.
To read an object from a file, the default constructor is called,
then object->Streamer. If you allocate objects in the default constructor,
you must be careful to not create the sub-objects twice when Streamer is called.

In the case of the Event example, we create a static TClonesArray at the first
call to the Event constructor, then we set the pointer fTracks to point to the
static pointer. This guarantees that the TClonesArray is created only once.

Rene Brun

Sylvie Dagoret-Campagne wrote:
> 
> hi,
> 
> I read in the user guide v0.7.2, chapter 11 the default
> constructor of a ROOT I/O class (deriving from TObject)
> should not allocate any memory
> (see the remark for T49Event class !)
> 
> But when I read the Event class default constructor, I see memory allocation
> but for a static pointer to a TClonesArray !
> 
> Why is it possible, what is the purpose in using static pointers ?
> 
> Regards .
> 
>                                 Sylvie
> 
> --
> Sylvie Dagoret-Campagne         | e-mail: dagoret@lpnhep.in2p3.fr,
> LPNHE, Universite Paris VI-VII  |      Sylvie.Dagoret-Campagne@lpnhep.in2p3.fr
> 4, Place Jussieu Tour 33, Rdc   | Telephone (33) 01 44 27 73 30
> 75252 PARIS CEDEX 05 - FRANCE   | Fax       (33) 01 44 27 46 38
>                                 | Standard  (33) 01 44 27 63 13



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:46 MET