Re: [wxpython-users] Simple scope question
by Phil Mayes other posts by this author
Jul 8 2008 3:57PM messages near this date
Re: [wxpython-users] Simple scope question
|
Re: [wxpython-users] Simple scope question
At 02:16 PM 7/8/2008, you wrote:
> I tried to reflect on what Chris wrote: being this one a matter of
> economy, it should be possible to calculate it, more or less accurately.
>
> Every window in a class has a name, even if sometimes it is the default
> name, and it has to be stored somewhere in memory. So to assign a specific
> name to a control doesn't unduly impinge on memory (unless we call our
> control Mr. Hasdrubal B. Weatherington Sr., Esq.).
>
> But even the programmer's time has its tiny value, and to write 400 times
> in an application
> self.FindWindowByName('grid')
> is more boring than
> self.grid
> while the cost for this leisure is the addition of the variable name to
> the memory: och aye, lads, with nowadays PCs I gather we can afford it.
>
> My only suggestion for the sanity of your mind, if you have more than a
> couple of these variables in your class, is not to declare them in
> __init__ , where they would get mixed up with a lot of other code, but
> write a sort of table at the beginning of the class, like:
> grid = None
> text = None
> combo = None
I worry more about performance than memory. It seems to me
that
self.FindWindowByname(name)
must execute way slower than
self.grid
> 2008/7/8 Christopher Barker
> <<mailto:Chris.Barker@[...].gov>Chris.Barker@[...].gov>:
> >
> >
> >raffaello wrote:
> >>Or assign a specific name to the grid in the constructor, as follows:
> >> grid = wx.grid.Grid(etc..., name = 'The Grid')
> >>and then get back the grid wherever you need it with the function:
> >> self.FindWindowByName('TheGrid').
> >>This second solution lessens the overhead on memory,
> >
> >by one reference -- which is tiny. And it adds the name reference to the
> >grid (or there always one there?), so it's negligible.
> >
> >
> > > so it is to be
> >>preferred for all controls that are called only now and then,
> >
> >I don't think it's preferred at all. I never use it, though if I were to,
> >it would be because I needed to reference the Window from somewhere far
> >away in the object hierarchy, making keeping a direct reference hard
> >(though that sound like a design in need of refactoring!)
> >
> >-Chris
> >
> >
> >--
> >Christopher Barker, Ph.D.
> >Oceanographer
> >
> >Emergency Response Division
> >NOAA/NOS/OR&R (206) 526-6959 voice
> >7600 Sand Point Way NE (206) 526-6329 fax
> >Seattle, WA 98115 (206) 526-6317 main reception
> >
> ><mailto:Chris.Barker@[...].gov>Chris.Barker@[...].gov
> >
> >_______________________________________________
> >wxpython-users mailing list
> ><mailto:wxpython-users@[...].org>wxpython-users@[...].org
> >http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
>
> _______________________________________________
> wxpython-users mailing list
> wxpython-users@[...].org
> http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
Thread:
John Dann
Raffaello
Phil Mayes
Robin Dunn
Raffaello
Robin Dunn
Timothy Grant
Josiah Carlson
Christopher Barker
Raffaello
Kyle W Rickey
|