Could someone please explain to me the intended difference between creating a TGraph through
or
?
I would think that both imply the same thing: please make me a TGraph, but I don’t know how many points it will hold so just initialize that size to zero. This is what TGraph(0) does. However, the default constructor TGraph() sets fNpoints = -1, which makes CtorAllocate() skip creation of the function list and return false. This looks like intended behaviour (especially since the comment mentions this as well) but I wonder why. It appears as if both ways create a valid TGraph, the only difference I have noticed so far is that (since TGraph() skips does not create a function list) the first kind of TGraph does never store fit results.
The two modes are equivalent, even if the memory allocation is happening at different times.
If you do not know the number of points when starting building the graph, ROOT will automatically accomodate enough space (doubling space) and setting the water mark.
It is of course more efficient to specify the exact number of points in the constructor when you can.
That’s what I thought, yes, the two should be equivalent. But one of the versions does not get a function list and cannot store fit results (for example). So the two constructors do not result in equivalent graphs.
This is correct. The default constructor is used by the I/O system. It cannot allocate objects like a TList* because these objects are created when reading a TGraph from a file.
It should be possible to extend TGraph to automatically create the TList when fitting a TGraph created via the default constructor.