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

Home » Public Forums » archive » losing pointers when concatenating array of structures
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
losing pointers when concatenating array of structures [message #94050] Sun, 08 January 2017 22:35 Go to previous message
MarioIncandenza is currently offline  MarioIncandenza
Messages: 231
Registered: February 2005
Senior Member
Hi IDL Wizards,

That topic is a mouthful, but I haven't encountered a tricky problem like this in a while, and I wanted your help to understand what's really going on here. Here's the code sample:

for i=0,1 do begin
undefine,struct
struct=create_struct('array',ptr_new(lindgen(i+1)))
if n_elements(structarray) eq 0 then structarray=struct else structarray=[structarray,struct]
help,*structarray[i].array ; looking for error
; this is where the error will happen
if(i gt 0) then help,*structarray[i-1].array
endfor
end

Here's the result:
% Compiled module: $MAIN$.
<PtrHeapVar23543>
LONG = Array[1]
<PtrHeapVar23544>
LONG = Array[2]
% Invalid pointer: <POINTER (<PtrHeapVar23543>)>.
% Execution halted at: $MAIN$ 9


Here's the fix:
if n_elements(structarray) eq 0 then structarray=temporary(struct) else structarray=[structarray,temporary(struct)]

If you use TEMPORARY(), this works. If you do not, it fails. Can someone help me understand this?

Happy New Year's everyone,

--Edward H.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Mismatch between video frame dimensions and stream using Coyote graphics
Next Topic: how to overplot a vertical line in the existing plot made using plot function?

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

Current Time: Sat Oct 11 05:47:22 PDT 2025

Total time taken to generate the page: 0.80158 seconds