I created a class with:
[..] private: Int_t nData; Int_t* iChan; //nData Float_t* fValue; //nData [..]
and I use the automatic streamer to do the class persistence (I use this class in TTree events)
I changed now the way i fill the variables of this class before inserting it in the tree. Now I don’t know a priori the total number of “nData”, but I add new data one by one, increasing nData each time. To avoid to reallocate the memory every time, i moved the memory allocation in the constructor (in all constructors, also the default one) in the following way (maybe not the best one, but surely the quickest):
iChan = new Int_t[MAX_POSSIBLE_NDATA] fValue = new Float_t[MAX_POSSIBLE_NDATA]
That means that the object keeps always the same (maximum possible) memory allocated.
I think the automatic streamer should continue writing ‘nData’ number of elements: in fact the size of object on disk (or inside a TTree event) seems not increased.
It seems also to work when i reopen the saved file and read again the TTree, but I can’t understand what is the action of automatic streamer when the object is read every event of the TTree for example during TTree::Draw(): is the default constructor executed before the automatic streamer, so MAX_POSSIBLE_NDATA is allocated, or do the automatic streamer the whole job, allocating only nData elements? (in the second case i obtained what i wanted…)
2nd question: at the moment i don’t need to add new elements when i reopen the file with TTree for analysis. If i reopen the file to update it, could i meet problem due this “shortcut”?