[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: IDLgrLegend broken
"David Fanning" <davidf@dfanning.com> wrote in message
news:MPG.14996ac0b9d231b2989cb0@news.frii.com...
Responding to David's post, and his quote from Pavel's post, which I have
not yet seen:
Pavel, quoted by David:
> > I think the only really generic solution is *saving each method in a
> > separate file*.
I think that this is not a good idea, because of this rule:
IDL searches--all the way up the inheritance tree--in memory before
searching on the disk. (For performance reasons, obviously.)
So if we have a class MyClass with a method SomeMethod stored in a file
myclass__somemethod.pro then the first time IDL wants to call SomeMethod on
a MyClass object it may find and compile myclass__somemethod.pro, but *only*
if the search through the already-compiled functions in memory fails to find
a SomeMethod associated with one of MyClass's superclasses.
The reason for storing all object methods in myclass__define.pro is that
myclass__define is always called (and so myclass__define.pro is always
compiled) when the first instance of MyClass is created. (Unless you get
sneaky and try to restore MyClass from disk.)
David:
> But before I did this, I'd have a closer read of this
> article, where JD and I (and probably Mark) discussed
> this restore object problem and came up with a
> "sorta" solution:
>
> http://www.dfanning.com/tips/saved_objects.html
Hey nice one David. I don't know that I can claim any of the credit or blame
for this article. I have read it before and I should have remembered its
existence before posting very similar material.
A comment/question on the RESOLVE_OBJ routine that's shown at the above
link:
The following code snippet ensures that each object's __define procedure is
called only if it has not already been compiled. (The array ri holds a list
of currently compiled routines, generated by a call to ROUTINE_INFO.)
if (where(ri eq defpro))[0] eq -1 then begin
;; Compile and define the class.
call_procedure,defpro
endif
My comment is: why bother? Once a __define method has been called once,
further calls have no effect.
---
Mark Hadfield
m.hadfield@niwa.cri.nz http://katipo.niwa.cri.nz/~hadfield/
National Institute for Water and Atmospheric Research
PO Box 14-901, Wellington, New Zealand