I’m trying to understand under what circumstances a variable should be declared as a pointer. For example, what would guide a programmer to choose between the following two ways of declaring a histogram?
TH1D *h = new TH1D("h","h",10,0,10); TH1D h("h","h",10,0,10);
I understand the difference in how to use them, at least at a basic level (such as using -> vs .), but I don’t understand why I would choose one method of initialization over another.
Many ROOT 6 objects prefer heap allocation: new and pointers, due to ROOT’s traditional memory management (e.g. the file owning the histograms). We are moving away from that; all of ROOT’s new and future classes (RDataFrame, RHist, RCanvas, RNtuple etc) happily live on the stack!