Pointers in IDL [message #39034] |
Tue, 13 April 2004 08:29 |
Benjamin Hornberger
Messages: 258 Registered: March 2004
|
Senior Member |
|
|
Hi all,
I still don't understand all aspects of pointers in IDL. 2 Questions:
1. What are null pointers for? I read that they can't be dereferenced. What
is their purpose then? The Gumley book writes (pg. 61): "Null pointers are
used when a pointer must be created, but the variable ... does not yet
exist." What would I do then when the variable does exist later and I want
the pointer to point to it? Wouldn't I use ptr_new(/allocate_heap) in the
first place, i.e. not create a null pointer but a pointer to an undefined
variable? Can anyone give an example when I would use ptr_new()?
2. If I point a pointer to a variable (e.g. *ptr=indgen(100)) and later
point it to a smaller variable (*ptr=indgen(50)), do I have a memory leak?
I.e., do I have to free it before I re-reference it?
I want to write a GUI which can open files which contain arrays of varying
size. Is it ok to define a pointer in the GUI to hold these arrays
(ptr=ptr_new(/allocate_heap)), and then whenever I open a new file, just
dereference to the new array (*ptr=array)? Or do I have to free the pointer
when I close one file and open another one?
Thanks for your help,
Benjamin
|
|
|