[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
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.)
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
> 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:
> 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.
a quick test of each method.
I did not use UNDEFINE procedure directly because it checks for
slows things down. I placed the Sz = SIZE(TEMPORARY(*myPtr)) statement
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:
Elapsed time to empty/fill list using method #1
Elapsed time to empty/fill list using method #2
Ratio of #2 / #1
X = Findgen(100)
A = PTR_NEW(X)
B = PTR_NEW(X)
Start1 = SysTime(/Seconds)
For i = 0L, 10000 Do Begin
If NOT Ptr_Valid(B) Then B = Ptr_NEW(X) Else *B = [*B, X]
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'
Ptr_Free, A, B
Bigelow Laboratory for Ocean Science
West Boothbay Harbor, Maine
note: email address new as of 25JULY2000