Re: IDL V5 and Pointers [message #9619] |
Wed, 23 July 1997 00:00 |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Charles Martin writes:
> I just started using pointers in IDL. Does anyone know how to get create a
> pointer that points to an existing variable, without duplicating the
> variable and without making it undefined?
>
> For example:
>
> x=findgen(1000,1000,1000) ; a big array
> ptr=ptr_new()
> ptr=&x ; this syntax is derived from C and is not valid in IDL.
It is not possible to create a pointer in IDL that points to
an existing variable without either (1) duplicating the variable, or
(2) making the variable undefined.
The reason for this, of course, is that IDL pointers are not
machine pointers like they are in C. That is to say, they
do not point directly to machine memory. They are special
heap variables, a way to have pointer-like operators in IDL
without the subsequent technical support nightmare real
machines pointers would cause.
Most of the time the distinction is completely moot.
For example, I might write the code above like this:
x = Ptr_New(Findgen(1000,1000,1000))
Then everywhere in the code where you use x I would
use *x. This makes it virtually transparent to the user.
Cheers,
David
------------------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
Customizable IDL Programming Courses
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com
IDL 5 Reports: http://www.dfanning.com/documents/anomaly5.html
|
|
|