Re: dynamical versus non dynamical for TH1F

From: John Idarraga <idarraga_at_cern.ch>
Date: Sat, 23 Jan 2010 23:18:17 -0500


Marc, try this with your code

valgrind --tool=callgrind ./myexecutable

you will get an output file called "callgrind.out.XXXX"

open it with

kcachegrind callgrind.out.XXXX

you will see what is going on ... calling 'new' and 'delete' 10^8 times takes most of the running time in this particular case.

cheers,

John

On Sat, 2010-01-23 at 23:55 +0100, Marc Escalier wrote:
> thanks for your comment,
>
> i agree, this is a advantage if the user "forgets".
>
> Anyway, with the mail of Andriy, i'm
> more and more considering that the dynamic allocation is "the best
> compromise" because the new() is actually not the part of the code which
> makes loose the more time. So the dynamicall allocation would make a
> tiny lost of time, while allowing to have the histograms not "deleted"
> after the end of the canvas
>
> regards
>
> ================
>
> On Sat, 23 Jan 2010, Tim Head wrote:
>
> > On 23 January 2010 15:23, Andriy Zatserklyaniy <zatserkl_at_gmail.com> wrote:
> >> Well known drawback of
> >>
> >> TH1F myhisto(...)
> >>
> >> is that, according to C++ rules, the object myhisto will be destroyed after
> >> exiting of scope, e.g. when your macro will terminate (if you draw this
> >> histogram in macro, the plot will disappear from TCanvas).
> >
> > A well known advantaged of not using new is that you don't leak memory ...
> >
> > but-you-already-know-this'ly yours
> > Tim
> >
> >>
> >> Cheers,
> >> Andrei.
> >>
> >> On Sat, Jan 23, 2010 at 10:48 AM, Marc Escalier <escalier_at_lal.in2p3.fr>
> >> wrote:
> >>>
> >>> Hello,
> >>>
> >>> i'm using a basic root program (.C) that allows to make some histograms of
> >>> variables of a given ntuple (a .root file)
> >>>
> >>> Up to now, i created the histogram dynamically with
> >>> TH1F *myhisto=new TH1F(...)
> >>>
> >>> i was wondering what it the more optimal (in terms of memory, cpu usage,
> >>> or any other criterious you know better than me) way to do ? :
> >>>
> >>> *this kind of dynamical allocation
> >>>
> >>> or
> >>>
> >>> *a non dynamical allocation
> >>> (i mean :
> >>> TH1F myhisto(...)
> >>> )
> >>>
> >>> (just in case : i do always the same plots and there variables are always
> >>> in the ntuple)
> >>>
> >>> thanks !
> >>>
> >>> (i'll reply in private to answers to prevent spamming you all)
> >>>
> >>
> >>
> >
> >
> >
> > --
> > http://tim.jottit.com/
> >
> >
>
Received on Sun Jan 24 2010 - 05:18:27 CET

This archive was generated by hypermail 2.2.0 : Sun Jan 24 2010 - 05:50:02 CET