global singleton object ? [message #26918] |
Tue, 02 October 2001 08:51  |
R.G.S.
Messages: 46 Registered: September 2000
|
Member |
|
|
Greetings,
partly inspired by the recent threads on global variables,
I have a question regarding a global object.
I have an IDL process that will run independently on several
different computers. So, I need a method of deciding what
computer and operating system I'm on, and defining various
filepaths etc. So I have written an object with methods such
as "->getfilepath". This method determines the computer name, and
returns the appropriate info. There are several methods, for different
read and write paths, and different data sets. The actual information is
hardcoded into the object definition.
So, I currently create the object and kill the object deep in each
basic read/write function, but I would much rather have one instance
of the object (i.e. the singleton object) that can be seen everywhere.
(I've used this approach many times in labview, and it is really handy).
I actually thought that objects were supposed to be of that scope, but
I guess I got confused with the Labview nonreentrant vis.
So, is there a way to easily define the object, or do I simply create it
upon startup of my IDL and define it to a system variable?
Cheers,
bobject
|
|
|
Re: global singleton object ? [message #26951 is a reply to message #26918] |
Wed, 03 October 2001 14:51  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
"Pavel A. Romashkin" <pavel.romashkin@noaa.gov> writes:
> Craig Markwardt wrote:
>>
>> Is there any reason these have to be posted as SAV files? You saved
>> it with IDL 5.5 which pretty much means you are catering to a *very*
>> exclusive crowd right now ... :-)
>
> Hey Craig,
> Now, that can't be right! They are 5.4! There was no 5.5 beta for the
> Mac, and I still can't set up IDL on my PC... I am always behind.
> I am afraid to post the code, I have an indication I may get banished
> from the NG. Well, *you* already have it from the sneaky use of your
> .sav hacking routines, so I risk the expulsion vote from you too, not
> only JD :-(
Well, two things happened. When I tried to restore it into IDL 5.2, I
got a bunch of error messages. When I tried it in IDL 5.3, and then
did HELP, none of the routines showed up, so I figured they weren't
loaded correctly. I was wrong! I did not realize that restored
procedures do not show up when you type HELP. I don't have easy
access to IDL 5.4 so don't you worry about being behind the times :-)
When I tried CMSAVEDIR, I got this result:
Date: 'Thu Sep 13 14:18:42 2001'
Username: 'Pavel Romashkin'
Hostname: 'pavelmacG4'
Arch: 'PowerMac'
OS: 'MacOS'
Release: '5.5'
Sure enough it says IDL 5.5 in the header. What happens when you
print, !VERSION?
Craig
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|
Re: global singleton object ? [message #26953 is a reply to message #26918] |
Wed, 03 October 2001 14:49  |
Mark Hadfield
Messages: 783 Registered: May 1995
|
Senior Member |
|
|
From: "JD Smith" <jdsmith@astro.cornell.edu>
> I think the idea of what multi-threading will bring is getting a bit
> carried away. I fully expect it to be limited to RSI-controlled code,
> and not configurable by the user. I.e., I don't suspect you'll be able
> to craft your own thread-aware routines, but rather rely on the internal
> multi-threading of certain built-in routines for increased speed.
> Someone please correct me if I'm wrong.
You are not wrong.
It will be interesting to see if it makes a significant difference in any
real-world code.
---
Mark Hadfield
m.hadfield@niwa.cri.nz http://katipo.niwa.cri.nz/~hadfield
National Institute for Water and Atmospheric Research
--
Posted from clam.niwa.cri.nz [202.36.29.1]
via Mailgate.ORG Server - http://www.Mailgate.ORG
|
|
|
Re: global singleton object ? [message #26955 is a reply to message #26918] |
Wed, 03 October 2001 13:55  |
Pavel A. Romashkin
Messages: 531 Registered: November 2000
|
Senior Member |
|
|
David Fanning wrote:
> P.S. And by the way, that check is in the mail. :-)
Oh yeah, right. If there's something I don't believe at all, this is it,
right here. I'd believe it if you said you sent me a bill for the lost wages.
> Yeah, but when I pointedly asked you how you did it,
> so I could fix the code up and claim it was my
> idea, you just waived your hands at me.
I did not! I told you! I am just waiting to get to that beer jug
together with you so I have at least *something* to show! And, now, who
promised that he will get to better things than working sometime in this life?
Cheers,
Pavel
|
|
|
Re: global singleton object ? [message #26959 is a reply to message #26918] |
Wed, 03 October 2001 13:38  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Pavel A. Romashkin (pavel.romashkin@noaa.gov) writes:
> P.S. My only hope is that David vote for me to stay, because I wrote
> those programs to totally avoid Common blocks ;-)
Yeah, but when I pointedly asked you how you did it,
so I could fix the code up and claim it was my
idea, you just waived your hands at me.
I'll have to think about it. I'll get back to you.
Cheers,
David
P.S. And by the way, that check is in the mail. :-)
--
David W. Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|
Re: global singleton object ? [message #26960 is a reply to message #26918] |
Wed, 03 October 2001 13:28  |
Pavel A. Romashkin
Messages: 531 Registered: November 2000
|
Senior Member |
|
|
Craig Markwardt wrote:
>
> Is there any reason these have to be posted as SAV files? You saved
> it with IDL 5.5 which pretty much means you are catering to a *very*
> exclusive crowd right now ... :-)
Hey Craig,
Now, that can't be right! They are 5.4! There was no 5.5 beta for the
Mac, and I still can't set up IDL on my PC... I am always behind.
I am afraid to post the code, I have an indication I may get banished
from the NG. Well, *you* already have it from the sneaky use of your
.sav hacking routines, so I risk the expulsion vote from you too, not
only JD :-(
Cheers,
Pavel
P.S. My only hope is that David vote for me to stay, because I wrote
those programs to totally avoid Common blocks ;-)
|
|
|
Re: global singleton object ? [message #26968 is a reply to message #26918] |
Wed, 03 October 2001 11:18  |
John-David T. Smith
Messages: 384 Registered: January 2000
|
Senior Member |
|
|
"Pavel A. Romashkin" wrote:
>
>> As for why a singleton is useful, just wait til IDL is multithreaded. When
>> you
>> have multiple processes that need acces to information (info that can be
>> changed by the user) then a singleton object is very nice! Very Very Nice.
>
> That probably will depend on what is allowed to be global between the
> threads. My singleton relies on a function being global, and heap memory
> addresses being global, too. Will each thread use separate heap
> addressing? Now, that and the synchronization of the threads is a
> separate can of worms that I have no knowledge about. It is almost the
> same as distributed computing, isn't it?
>
I think the idea of what multi-threading will bring is getting a bit
carried away. I fully expect it to be limited to RSI-controlled code,
and not configureable by the user. I.e., I don't suspect you'll be able
to craft your own thread-aware routines, but rather rely on the internal
multi-threading of certain built-in routines for increased speed.
Someone please correct me if I'm wrong.
JD
|
|
|