array of structures with pointers [message #84203] |
Mon, 06 May 2013 10:31 |
wlandsman
Messages: 743 Registered: June 2000
|
Senior Member |
|
|
I think I am having brain freeze this morning.
I want to make an array of structures, where each includes a pointer.
IDL> st = {flux:ptr_new(/all)} ;Create a structure with a pointer
IDL> st = replicate(st,20) ;I want a structure with 20 elements
IDL> *st[0].flux = 3.2 ;Assign a value to the zeroth structure element
IDL> print,*st[4].flux ;What?? - the fourth structure element also gets this value
3.20000
OK, I can figure out what is going on.
IDL> st = {flux:ptr_new(/all)} ;Create a structure with a pointer
IDL> st = replicate(st,20) ;I want a structure with 20 elements
IDL> help,st[0].flux
<Expression> POINTER = <PtrHeapVar40>
IDL> help,st[4].flux
<Expression> POINTER = <PtrHeapVar40>
Ah, so when I replicated the pointers, they all point to the same location. So when I update the value in this location once, all the pointers will be updated. So I understand what happened but how do I get what I want -- for each structure tag in the array to be an independent pointer?
Thanks, ---Wayne
P.S. I now think I want the flux tag to be a LIST(), but I would still like to know how to make a structure array with independent pointers.
|
|
|