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

Home » Public Forums » archive » Re: help with structure
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: help with structure [message #70288] Wed, 31 March 2010 18:50
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
On Mar 31, 8:13 pm, David Fanning <n...@dfanning.com> wrote:
> pp writes:
>> Yes, it is. But I think the question was how to make an array where
>> each element pointed to a different heap variable. So that when he
>> assigns the non-temp thing that will go into the pointer target, it
>> will be a different heap variable for each element of the array. And a
>> better answer to this problem actually is what Gray wrote above.
>
> Ah, I see what you mean now. Yes, that could probably use
> an article. Thanks for the clarification.


There was a similar thread a few months ago:


http://groups.google.com/group/comp.lang.idl-pvwave/browse_t hread/thread/b8b10aaae8d514dc
Re: help with structure [message #70289 is a reply to message #70288] Wed, 31 March 2010 16:13 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
pp writes:

> Yes, it is. But I think the question was how to make an array where
> each element pointed to a different heap variable. So that when he
> assigns the non-temp thing that will go into the pointer target, it
> will be a different heap variable for each element of the array. And a
> better answer to this problem actually is what Gray wrote above.

Ah, I see what you mean now. Yes, that could probably use
an article. Thanks for the clarification.

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: help with structure [message #70290 is a reply to message #70289] Wed, 31 March 2010 15:47 Go to previous message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
On Mar 31, 7:37 pm, David Fanning <n...@dfanning.com> wrote:
> pp writes:
>> I suppose he means that by doing that, after the replicate(), all
>> elements of a point to the same two heap variables.
>
> I guess I don't follow you. Isn't this the meaning
> of "replicate"?

Yes, it is. But I think the question was how to make an array where
each element pointed to a different heap variable. So that when he
assigns the non-temp thing that will go into the pointer target, it
will be a different heap variable for each element of the array. And a
better answer to this problem actually is what Gray wrote above.
Re: help with structure [message #70291 is a reply to message #70290] Wed, 31 March 2010 15:42 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
David Fanning writes:

>
Oh, wait, maybe this is what you mean:

IDL> print, *a[25].field
5

Yes, I can see how that could be a problem.

Cheers,

David

> pp writes:
>
>> I suppose he means that by doing that, after the replicate(), all
>> elements of a point to the same two heap variables.
>
> I guess I don't follow you. Isn't this the meaning
> of "replicate"?
>
>> There is no way
>> around it, he needs to loop on the elements to set the pointer on each
>> one to point to something new.
>
> Well, yes, but what else would he be doing?
>
> Perhaps you (and he) mean to replicate a valid pointer
> that points to nothing yet:
>
> IDL> struct ={field:Ptr_New(/ALLOCATE_HEAP)}
> IDL> a = Replicate(struct, 100)
> IDL> Print, Ptr_Valid(a[50].field)
> 1
> IDL> *a[50].field = 5
>
> Just confused, I guess. :-(
>
> Cheers,
>
> David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: help with structure [message #70292 is a reply to message #70291] Wed, 31 March 2010 15:37 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
pp writes:

> I suppose he means that by doing that, after the replicate(), all
> elements of a point to the same two heap variables.

I guess I don't follow you. Isn't this the meaning
of "replicate"?

> There is no way
> around it, he needs to loop on the elements to set the pointer on each
> one to point to something new.

Well, yes, but what else would he be doing?

Perhaps you (and he) mean to replicate a valid pointer
that points to nothing yet:

IDL> struct ={field:Ptr_New(/ALLOCATE_HEAP)}
IDL> a = Replicate(struct, 100)
IDL> Print, Ptr_Valid(a[50].field)
1
IDL> *a[50].field = 5

Just confused, I guess. :-(

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: help with structure [message #70293 is a reply to message #70292] Wed, 31 March 2010 15:12 Go to previous message
Gray is currently offline  Gray
Messages: 253
Registered: February 2010
Senior Member
On Mar 31, 5:49 pm, pp <pp.pente...@gmail.com> wrote:
> On Mar 31, 6:40 pm, David Fanning <n...@dfanning.com> wrote:
>
>
>
>
>
>> Sumit writes:
>>> I want to create a structure with 2 fields. The fields need to be of
>>> variable length. I need to have 'n' such structures,where 'n' is
>>> scalar number. To address the issue of variable length field, I create
>>> pointers for each field( pointing to variable temp for initialization)
>>> as shown below:
>>> mystruct={l1:ptr_new(temp), l2:ptr_new(temp)}
>>> I don't know how to create  copies of this structure. Replicate
>>> doesn't work as I guess it creates shallow copy.
>
>> What do you mean it "doesn't work"?
>
>> IDL> mystruct={l1:ptr_new(temp), l2:ptr_new(temp)}
>> IDL> a= replicate(mystruct, 100)
>> IDL> help, a
>> A               STRUCT    = -> <Anonymous> Array[100]
>> IDL> a[50].l2 = Ptr_New(findgen(11))
>
> I suppose he means that by doing that, after the replicate(), all
> elements of a point to the same two heap variables. There is no way
> around it, he needs to loop on the elements to set the pointer on each
> one to point to something new.

Or, he can just create the struct array without allocating heap
variables, then set that field of the array to a ptrarr, and allocate
the heaps then.

IDL> mystruct={11:ptr_new(),12:ptr_new()}
IDL> a=replicate(mystruct,100)
IDL> a.11 = ptrarr(100,/allocate_heap)
IDL> a.12 = ptrarr(100,/allocate_heap)

Since he's initializing with temporary variables anyway (at least
that's how I read the "temp" in the original post), it doesn't matter
that the heaps aren't initialized doing it this way.
Re: help with structure [message #70294 is a reply to message #70293] Wed, 31 March 2010 14:49 Go to previous message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
On Mar 31, 6:40 pm, David Fanning <n...@dfanning.com> wrote:
> Sumit writes:
>> I want to create a structure with 2 fields. The fields need to be of
>> variable length. I need to have 'n' such structures,where 'n' is
>> scalar number. To address the issue of variable length field, I create
>> pointers for each field( pointing to variable temp for initialization)
>> as shown below:
>> mystruct={l1:ptr_new(temp), l2:ptr_new(temp)}
>> I don't know how to create  copies of this structure. Replicate
>> doesn't work as I guess it creates shallow copy.
>
> What do you mean it "doesn't work"?
>
> IDL> mystruct={l1:ptr_new(temp), l2:ptr_new(temp)}
> IDL> a= replicate(mystruct, 100)
> IDL> help, a
> A               STRUCT    = -> <Anonymous> Array[100]
> IDL> a[50].l2 = Ptr_New(findgen(11))

I suppose he means that by doing that, after the replicate(), all
elements of a point to the same two heap variables. There is no way
around it, he needs to loop on the elements to set the pointer on each
one to point to something new.
Re: help with structure [message #70295 is a reply to message #70294] Wed, 31 March 2010 14:40 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Sumit writes:

> I want to create a structure with 2 fields. The fields need to be of
> variable length. I need to have 'n' such structures,where 'n' is
> scalar number. To address the issue of variable length field, I create
> pointers for each field( pointing to variable temp for initialization)
> as shown below:
> mystruct={l1:ptr_new(temp), l2:ptr_new(temp)}
> I don't know how to create copies of this structure. Replicate
> doesn't work as I guess it creates shallow copy.

What do you mean it "doesn't work"?

IDL> mystruct={l1:ptr_new(temp), l2:ptr_new(temp)}
IDL> a= replicate(mystruct, 100)
IDL> help, a
A STRUCT = -> <Anonymous> Array[100]
IDL> a[50].l2 = Ptr_New(findgen(11))

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: help with structure
Next Topic: Re: gripe about structures

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

Current Time: Fri Oct 10 14:23:31 PDT 2025

Total time taken to generate the page: 1.43734 seconds