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

Home » Public Forums » archive » Re: renaming a variable without making a copy
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: renaming a variable without making a copy [message #68923 is a reply to message #68922] Tue, 08 December 2009 14:39 Go to previous messageGo to previous message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
Kenneth P. Bowman wrote:
> In article <MPG.2587fff16b170da398968a@news.giganews.com>,
> David Fanning <news@dfanning.com> wrote:
>
>> newName = Temporary(oldName)
>
> Can anyone explain to me what TEMPORARY actually does? The documentation
> says
>
> The TEMPORARY function returns a temporary copy of a variable, and sets
> the original variable to "undefined".
>
> which makes no sense to me at all. Doesn't making a "temporary copy
> of a variable" occupy memory? Perhaps I am confused by the use of the name
> "TEMPORARY".

TEMPORARY modifies the metadata of the variable passed to it, i.e., by
erasing its name and marking it as a temporary variable. All the other
metadata and the actual data can stay put.

> My concept of an IDL variable (which could easily be wrong) is: some
> metadata that describes the variable (what you get with the SIZE function)
> and the actual data that comprises the variable. These things could be
> in different places in memory, and the metadata could contain, for example,
> a pointer to the actual data. Most of the time, I don't need to know.

There's some other metadata and things depend on whether the variable is
an array or structure and what type it is, but this is basically correct.

> Does TEMPORARY wipe out the old metadata (replacing it with
> "undefined") and create new "unnamed" metadata that points to the data part
> of the destroyed variable?
>
> The example in the Docs is not very revealing.
>
> Why does
>
> A = TEMPORARY(A) + 1
>
> use less memory than
>
> A = A + 1
>
> ??
>
> I suppose there is a good reason that the latter example "creates a new
> array for the result of the addition, places the sum into the new array,
> assigns it to A, and then frees the old allocation of A", although it
> just seems to me like the interpreter is being obtuse.

The interpreter probably could look for these things and optimize, but
generally when it sees an expression like A + 1 it must create a
temporary variable to hold the result. Only later does it see that this
will be assigned back to A.

IDL can handle temporary variables differently. It knows the result of
the expression

tempVar + 1

can be placed right back into the temporary variable. It also knows that
when assigning a temporary variable to a new variable name, as in

A = temporary(A) + 1

the "assignment" can just attached the name "A" and change the metadata
of the variable to indicate that it is no longer a temporary variable.

Mike
--
www.michaelgalloy.com
Research Mathematician
Tech-X Corporation
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: journal call broken with 7.x
Next Topic: Re: Apropos of Nothing

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

Current Time: Wed Oct 08 17:15:33 PDT 2025

Total time taken to generate the page: 0.00812 seconds