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

Home » Public Forums » archive » Delvar?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Delvar? [message #31369 is a reply to message #31225] Fri, 28 June 2002 12:01 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
William (wmc@bas.ac.uk) writes:

> OK, I've read it, but I have only a vague idea of why:
>
> tempvar = Size(Temporary(varname))
>
> works to delete varname...

Alright. First of all, this code is inside a procedure.
That's important. UNDEFINE looks like this:

;*********************************************************** *********
PRO UNDEFINE, varname
IF (N_Elements(varname) NE 0) THEN tempvar = Size(Temporary(varname))
END
;*********************************************************** *********

The variable varname is passed in by reference. So anything
we do to it inside the procedure will affect it outside the
procedure as well. In your case, you are passing the variable
image into this procedure:

Undefine, image

What we do is undefine varname by using it as an argument
to the TEMPORARY function, returning something of similar
size and type for the SIZE function to digest. But when SIZE
is finished, varname is undefined.

But, of course, we have created the variable tempvar, which
is a bit bigger than our original image = 0 problem we started
with. But, since we are inside a procedure, any memory allocated
to tempvar is release once the procedure exits. The result is
that we have completely undefined the variable varname (and,
because it was passed by reference, the variable image), and
we no have all the memory originally associated with image
available to re-use in our program.

Plus, if you use the variable image subsequently in an expression,
you will get the message that "image is undefined" rather than
something else that would make absolutely no sense in the
context of your program. It just looks a whole lot cleaner
and you can see at a glance in your code what you are doing. :-)

Cheers,

David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
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
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: gamma correction
Next Topic: Re: Defining constants in IDL?

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

Current Time: Fri Oct 10 16:04:09 PDT 2025

Total time taken to generate the page: 0.72087 seconds