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 
Switch to threaded view of this topic Create a new topic Submit Reply
Delvar? [message #31225] Fri, 28 June 2002 04:09 Go to next message
wmconnolley is currently offline  wmconnolley
Messages: 106
Registered: November 2000
Senior Member
I understand that I can't use delvar in subroutines, only at the
main prompt. But if I do verybigarray=0, does that get rid of the
memory usage anyway?

-W.

--
William M Connolley | wmc@bas.ac.uk | http://www.nerc-bas.ac.uk/icd/wmc/
Climate Modeller, British Antarctic Survey | Disclaimer: I speak for myself
I'm a .signature virus! copy me into your .signature file & help me spread!
Re: Delvar? [message #31360 is a reply to message #31225] Fri, 28 June 2002 14:35 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Craig Markwardt (craigmnet@cow.physics.wisc.edu) writes:

> Actually I like the SIZE() function there. If VARNAME is a large
> array, then you are just wasting cycles copying it to TEMPVAR, only to
> have it erased a moment later when the UNDEFINE procedure returns.

If I understand my source correctly (and believe me, this
guy ought to know) there is really no copying going on.
More like pointer re-positioning. But I have to admit,
I've never really noticed a huge slow-down using *any* of
these methods. ;-)

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
Re: Delvar? [message #31363 is a reply to message #31225] Fri, 28 June 2002 14:07 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
David Fanning <david@dfanning.com> writes:

> David Fanning (david@dfanning.com) writes:
>
>> 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
>> ;*********************************************************** *********
>
> Oh, oh. I think my problem is that I'm not anal enough. :-(
>
> It was gently pointed out to me that, uh, the SIZE function
> isn't really doing anything worthwhile here, so why put
> it in?

Hi David--

Actually I like the SIZE() function there. If VARNAME is a large
array, then you are just wasting cycles copying it to TEMPVAR, only to
have it erased a moment later when the UNDEFINE procedure returns.

What I do often enough is the following slight variation.

;*********************************************************** *********
PRO UNDEFINE, varname
varname = 0
tempvar = temporary(varname)
END
;*********************************************************** *********

This assures that the memory associated with VARNAME is released
first, and then the TEMPORARY() call is only there to release the "0".
In the line-count contest with you, I lose, but in the character count
contest, I win!

Craig

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: Delvar? [message #31368 is a reply to message #31225] Fri, 28 June 2002 13:18 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
David Fanning (david@dfanning.com) writes:

> 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
> ;*********************************************************** *********

Oh, oh. I think my problem is that I'm not anal enough. :-(

It was gently pointed out to me that, uh, the SIZE function
isn't really doing anything worthwhile here, so why put
it in?

My only excuse is that you know how these things go.
You're standing around glaring at that &#*@ down-the-line
backhand that went long *again*, and an idea suddenly
comes to you. By the time you get back to the office
the sudden clarity has turned to mush and you cast around
for inspiration. In the end, the final result contains
unmistakable marks of your own muddleheadedness.

But this is only version two of a three line program. I must
be a better programmer than I think. It usually takes me at
least five versions to get it right. :-)

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

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
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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: gamma correction
Next Topic: Re: Defining constants in IDL?

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

Current Time: Thu Oct 09 07:54:17 PDT 2025

Total time taken to generate the page: 0.71771 seconds