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

Home » Public Forums » archive » Structure field concatenation
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Structure field concatenation [message #21706 is a reply to message #21614] Mon, 11 September 2000 15:28 Go to previous message
Ben Tupper is currently offline  Ben Tupper
Messages: 186
Registered: August 1999
Senior Member
Hello,

Geez, you post such great stuff. Thank you for taking the time to do so.

I hadn't thought that the empty list method I lean on was awkward until you
mentioned it... now I'm all thumbs. I can see the utility in each
method you
outline.

I don't know how David deals with emptied lists, but here's how I
usually do it.
In general, when a list must be emptied, I have employed the UNDEFINE procedure
(available from David's or Martin's website.)

UNDEFINE, *myPtr

The UNDEFINE procedure calls the SIZE() function...

Sz = SIZE(TEMPORARY(*myPtr))

I test the emptiness of a pointer with N_ELEMENTS() before adding to the list...

If N_ELEMENTS(*Ptr) EQ 0 then *Ptr = NewValue Else *Ptr = [*Ptr, NewValue]


"J.D. Smith" wrote:

>
> Also, how is an undefined pointer created manually after the fact -- i.e., how
> do you "empty" am already filled list? Something awkward like:
>
> ptr_free, theValue
> theValue=ptr_new(/alloc)
>
> where I would only need the first line. To be fair to the advantages of the
> Undefined method... if changing the pointed-to value altogether, they need only:
>
> *theValue=newvalue
>
> whereas I require:
>
> if ptr_valid(theValue) then *theValue=newvalue else theValue=ptr_new(newvalue)
>

I was curious about the time it takes to run method 1 versus method 2.
Below is
a quick test of each method.
I did not use UNDEFINE procedure directly because it checks for
arguments which
slows things down. I placed the Sz = SIZE(TEMPORARY(*myPtr)) statement
in its
stead.

There doesn't seem to be any time difference, which makes suspicious
that I don't
have a good test here. (BTW, the ratio is 2.2 if I call UNDEFINE,
which I usually
do.) Here are the results:

IDL> list_ptr
Elapsed time to empty/fill list using method #1
0.066666603 seconds
Elapsed time to empty/fill list using method #2
0.066666603 seconds
Ratio of #2 / #1
1.0000000



Ben

;------START
PRO LIST_PTR

X = Findgen(100)

A = PTR_NEW(X)
B = PTR_NEW(X)

Start1 = SysTime(/Seconds)
For i = 0L, 10000 Do Begin
Ptr_Free, B
If NOT Ptr_Valid(B) Then B = Ptr_NEW(X) Else *B = [*B, X]
EndFor
Fini1= SysTime(/Seconds)

Print, 'Elapsed time to empty/fill list using method #1'
Print, Fini1-Start1, ' seconds'

Start2 = SysTime(/Seconds)
For i = 0L, 10000 Do begin
tempvar = SIZE(TEMPORARY(*A))
If N_elements(*A) EQ 0 Then *A = X Else *A = [*A,X]
EndFor
Fini2 = Systime(/Seconds)

Print, 'Elapsed time to empty/fill list using method #2'
Print, Fini2-Start2, ' seconds'


Print, 'Ratio of #2 / #1'
print, (Fini2-Start2)/(Fini1-Start1)

Ptr_Free, A, B
END
;----------END



--
Ben Tupper
Bigelow Laboratory for Ocean Science
West Boothbay Harbor, Maine
btupper@bigelow.org
note: email address new as of 25JULY2000
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: IDLgrROI and normalized coords
Next Topic: Re: taking the widget plunge. help

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

Current Time: Thu Oct 09 21:07:25 PDT 2025

Total time taken to generate the page: 0.39989 seconds