comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: large info structure?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: large info structure? [message #56107] Wed, 03 October 2007 01:06 Go to next message
Wox is currently offline  Wox
Messages: 184
Registered: August 2006
Senior Member
On Tue, 02 Oct 2007 15:10:57 -0000, markb77@gmail.com wrote:

> I've finished writing the front end and now I'm in the process of
> adding some analysis. What I'm noticing is that the info structure
> that gets passed around between event handlers is getting to be very
> large. Mine is up to 130 variables, at the moment.

How does this "info structure gets passed around between event
handlers?" Where is this stored? Are you worried by the program
copying this large structure on every event?

I'm not sure what your situation is, but suppose you have the info
structure stored in the top level widget, you can access it without
copying, like this:

pro event_handler,ev
widget_control,ev.top,get_uvalue=infostruct,/NO_COPY
...[handle event: make sure there is no return here!]...
widget_control,ev.top,set_uvalue=infostruct,/NO_COPY
end

If you don't like the /NO_COPY idea, you can for example have a
pointer (created with ptr_infostruct=ptr_new(infostruct) ) to your
info structure as UVALUE of the top level widget:

pro event_handler,ev
widget_control,ev.top,get_uvalue=ptr_infostruct
...[handle event: reffer to fields as (*ptr_infostruct).(i) ]...
end
Re: large info structure? [message #56110 is a reply to message #56107] Tue, 02 October 2007 14:35 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
markb77@gmail.com writes:

> David - thanks for the advice, btw, but I'm just getting my head
> around widget programming.. not quite ready for full on OO programming
> yet

Well, I can tell you are headed in that direction. :-)

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: large info structure? [message #56111 is a reply to message #56110] Tue, 02 October 2007 14:16 Go to previous messageGo to next message
markb77 is currently offline  markb77
Messages: 217
Registered: July 2006
Senior Member
On Oct 2, 11:42 am, David Fanning <n...@dfanning.com> wrote:

> Ahhmumm, may I suggest writing your widget program as an object? :-)
>

David - thanks for the advice, btw, but I'm just getting my head
around widget programming.. not quite ready for full on OO programming
yet

Mark
Re: large info structure? [message #56112 is a reply to message #56111] Tue, 02 October 2007 14:08 Go to previous messageGo to next message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
David Fanning wrote:
> markb77@gmail.com writes:
>
>> I see many examples of widget event handlers that identify the widget
>> generating the event by checking its UVALUE. It seems redundant to
>> store a name in both the UVALUE and the UNAME of each widget. Is
>> there any disadvantage to using a statement like this:
>>
>> widget = widget_info(event.id, /UNAME)
>>
>> to get the source of the event?
>
> The only disadvantage I see is that there are considerably more
> opportunities to screw up string comparisons in CASE
> statements and the like then there are with numbers. But
> if you are careful and ALWAYS stick to a particular case
> for the names, etc. you should be able to cope.

Do you mean a particular case for the the uname/uvalue names, or the case comparison
expression (and the like)? It's almost purely a matter of style, but I prefer the latter, e.g.

string = 'ThIsCaSe' ; case irrelevant...whatever looks nice :o)

CASE STRUPCASE(string) OF
'THISCASE':....
'THATCASE':....
ELSE:...
ENDCASE

I guess one could argue it's self-documenting and localises any confusion over the
convention chosen, but, eh <shrug>.

Anyway...

cheers,

paulv
Re: large info structure? [message #56113 is a reply to message #56112] Tue, 02 October 2007 13:48 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
markb77@gmail.com writes:

> I see many examples of widget event handlers that identify the widget
> generating the event by checking its UVALUE. It seems redundant to
> store a name in both the UVALUE and the UNAME of each widget. Is
> there any disadvantage to using a statement like this:
>
> widget = widget_info(event.id, /UNAME)
>
> to get the source of the event?

The only disadvantage I see is that there are considerably more
opportunities to screw up string comparisons in CASE
statements and the like then there are with numbers. But
if you are careful and ALWAYS stick to a particular case
for the names, etc. you should be able to cope.

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: large info structure? [message #56118 is a reply to message #56113] Tue, 02 October 2007 13:25 Go to previous messageGo to next message
markb77 is currently offline  markb77
Messages: 217
Registered: July 2006
Senior Member
I like the idea of storing widget names in the UNAME of the widget and
then using that name to find the ID... I've actually made that change
already and am still left with 130 !

Another question though,

I see many examples of widget event handlers that identify the widget
generating the event by checking its UVALUE. It seems redundant to
store a name in both the UVALUE and the UNAME of each widget. Is
there any disadvantage to using a statement like this:

widget = widget_info(event.id, /UNAME)

to get the source of the event?

thanks,
Mark
Re: large info structure? [message #56119 is a reply to message #56118] Tue, 02 October 2007 10:52 Go to previous messageGo to next message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
On Oct 2, 9:10 am, mark...@gmail.com wrote:
> Hi,
>
> I'm writing a widget application which will serve as a data analysis
> platform for scientific image data. The idea is that after loading
> the image, there are many different types of analysis that the user
> may wish to run on it, and this application will support them all.
> There will be an 'Analysis' dropdown menu, for instance, with several
> options. I also want to make it easy to add new analysis methods to
> the program.
>
> I've finished writing the front end and now I'm in the process of
> adding some analysis. What I'm noticing is that the info structure
> that gets passed around between event handlers is getting to be very
> large. Mine is up to 130 variables, at the moment.
>
> Does anyone have a strategy to suggest for dealing with this type of
> situation? I'm worried that this info data will spiral out of
> control. I was thinking that I could break down the info data into a
> bunch of smaller structures, and hold pointers to each of those
> structures in one higher level info structure..
>
> thanks,
> Mark

Not sure what you are storing, but you can eliminate storing any
widget identifiers by giving each widget you want to store a UNAME:

myWidget = widget_draw(parent, uname='my_uname', ...)

and then using:

widgetID = widget_info(event.top, find_by_uname='my_uname')

to get the ID later when you need it.

Mike
--
www.michaelgalloy.com
Re: large info structure? [message #56120 is a reply to message #56119] Tue, 02 October 2007 09:56 Go to previous messageGo to next message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
David Fanning wrote:
> markb77@gmail.com writes:
>
>> I'm writing a widget application which will serve as a data analysis
>> platform for scientific image data. The idea is that after loading
>> the image, there are many different types of analysis that the user
>> may wish to run on it, and this application will support them all.
>> There will be an 'Analysis' dropdown menu, for instance, with several
>> options. I also want to make it easy to add new analysis methods to
>> the program.
>>
>> I've finished writing the front end and now I'm in the process of
>> adding some analysis. What I'm noticing is that the info structure
>> that gets passed around between event handlers is getting to be very
>> large. Mine is up to 130 variables, at the moment.
>>
>> Does anyone have a strategy to suggest for dealing with this type of
>> situation?
>
> Ahhmumm, may I suggest writing your widget program as an object? :-)
>
> It doesn't solve the "lots of info" problem, but it
> does mean you don't have to pass anything around anymore.
> It is ALL built right into the fabric of the program.
>
> And the "lots of info" problem eventually gets sorted out
> into a "several objects" solution, which tends to compartmentalize
> the functionality and keep things from breaking when adding new
> functionality.
>
> There is a danger to this kind of programming, however. It is
> easy (WAY too easy!) to make your objects "clever". Which is
> good, don't get me wrong. But clever objects make it almost
> impossible to follow the programming flow.

Huh. I read something similar about ruby code the other day also. The real cleverly
written ruby codes tends to have many methods that don't seem to actually *do* anything -
they just call other methods, which call others, etc..

Of course, I'm mostly still in the monolithic block-o-code stage wrt ruby. :o(

cheers,

paulv
Re: large info structure? [message #56124 is a reply to message #56120] Tue, 02 October 2007 08:42 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
markb77@gmail.com writes:

> I'm writing a widget application which will serve as a data analysis
> platform for scientific image data. The idea is that after loading
> the image, there are many different types of analysis that the user
> may wish to run on it, and this application will support them all.
> There will be an 'Analysis' dropdown menu, for instance, with several
> options. I also want to make it easy to add new analysis methods to
> the program.
>
> I've finished writing the front end and now I'm in the process of
> adding some analysis. What I'm noticing is that the info structure
> that gets passed around between event handlers is getting to be very
> large. Mine is up to 130 variables, at the moment.
>
> Does anyone have a strategy to suggest for dealing with this type of
> situation?

Ahhmumm, may I suggest writing your widget program as an object? :-)

It doesn't solve the "lots of info" problem, but it
does mean you don't have to pass anything around anymore.
It is ALL built right into the fabric of the program.

And the "lots of info" problem eventually gets sorted out
into a "several objects" solution, which tends to compartmentalize
the functionality and keep things from breaking when adding new
functionality.

There is a danger to this kind of programming, however. It is
easy (WAY too easy!) to make your objects "clever". Which is
good, don't get me wrong. But clever objects make it almost
impossible to follow the programming flow. (Have you ever tried
to figure out how something works in the iTool system?) So I would
resist the clever solution whenever possible and write really, really
simple solutions. Six months from now, you will be VERY glad you
did! :-)

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: large info structure? [message #56165 is a reply to message #56110] Fri, 05 October 2007 08:01 Go to previous message
Mike[2] is currently offline  Mike[2]
Messages: 99
Registered: December 2005
Member
On Oct 2, 5:35 pm, David Fanning <n...@dfanning.com> wrote:
> mark...@gmail.com writes:
>> David - thanks for the advice, btw, but I'm just getting my head
>> around widget programming.. not quite ready for full on OO programming
>> yet
>
> Well, I can tell you are headed in that direction. :-)

Yes - it is inevitable that all will be assimilated!

Mark - A suggestion for those who are interested, but are hesitating
to go down the object path:

Pick a project that you are in the process of implementing, or even
better, something that you wrote a while back and have to update.
Make sure that it is relevant - not just a toy code, but something
that you will actually use - some library of non-trivial calculations
for example. If you are passing around lots of variables and/or large
structures and finding adding new variables to be a real pain, that
would be perfect.

Do some reading and studying up on objects (not about IDL objects, but
object orientation in general - objects are not about implementation
details and syntax, but about design). I got a lot out of reading
"Object Oriented Software Construction" by Meyer, but I'm sure there
are other things available as well. I think it is key to learn the
background without getting locked into some particular language's
implementation and syntax.

Then learn the IDL details and syntax for objects and rewrite or
extend your code using them (or whatever language you are using -
originally I did this with python).

I'll bet you'll get hooked and learn enough to be fully ready for it.

Mike
Re: large info structure? [message #56181 is a reply to message #56107] Thu, 04 October 2007 15:40 Go to previous message
JD Smith is currently offline  JD Smith
Messages: 850
Registered: December 1999
Senior Member
> pro event_handler,ev
> widget_control,ev.top,get_uvalue=infostruct,/NO_COPY
> ...[handle event: make sure there is no return here!]...
> widget_control,ev.top,set_uvalue=infostruct,/NO_COPY
> end

Or, more aptly:

; make sure there is no return here, or any error or other stoppage

The problem with this NO_COPY method is that if any sort of stop,
including an error, happens while the event is being handled, your widget
program is "broken" and must be restarted, since the info UVALUE has gone
missing. If instead you store state information in a permanent place,
like on the pointer or object heap, you can easily patch up your broken
event code, retall, and continue where you left off. *So* much nicer for
development. I vote to ban /NO_COPY from general recommendation. It's a
bit more cumbersome to replace infostruct.x with (*infoptr).x, which is of
course why object widgets are so attractive (self.x).

JD
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: envi_setup_head for TIFF
Next Topic: What is the main difference between a script and a procedure?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:56:44 PDT 2025

Total time taken to generate the page: 0.00724 seconds