[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Structure field concatenation


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

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

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



X = Findgen(100)


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]
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]
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

Ben Tupper
Bigelow Laboratory for Ocean Science
West Boothbay Harbor, Maine
     note: email address new as of 25JULY2000