Re: compile a routine wich inlude a commun [message #47132 is a reply to message #47067] |
Tue, 24 January 2006 00:09   |
peter.albert@gmx.de
Messages: 108 Registered: July 2005
|
Senior Member |
|
|
Just my 2 cents: imho, the problem with the given example
p=ptr_new(x[1:2,1:2])
is that x[1:2, 1:2] on the right hand side of the equation is, if I
remember correctly, actually a new temporary variable. So p is pointing
to a temporary variable which has nothing in commion with the variable
x, apart from the fact that its initial values equal the appropriate
ones of x. After that, any operation on p is totally disconnected to x.
On the other hand, Davids example used
p = ptr_new(x)
and here, p is actually pointing to the memory space occupied by x, so
modifying *p actually does modify x.
And yes, for this little example the effect is the same when using
temporary() two times, as Paul suggested. But this is not the, umh,
only point of pointers. I can hardly imagine how something like Davids
highly appreciated linked list object would work using temporary()
instead of pointers.
But well, looking at Pauls original wish of using pointers to alias
subsets of an array; given the fact that x[...] actually creates a new
temporary variable makes me feel that this is actually not possible in
IDL. Of course, there might be a way using histogram ...
Cheers,
Peter
|
|
|