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

Home » Public Forums » archive » Re: taming the shrew, a.k.a. structure
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: taming the shrew, a.k.a. structure [message #26045 is a reply to message #26001] Tue, 31 July 2001 16:26 Go to previous messageGo to previous message
david[2] is currently offline  david[2]
Messages: 100
Registered: June 2001
Senior Member
Todd Clements writes:

> Pointers
> are fun and useful things, but that also means that you have to worry
> about cleaning them up when you're done.
>
> myStruct = {myStruct, array1: ptr_new()}
>
> Then, in your code:
>
> myStruct.array1 = ptr_new( fltarr( startSize ) )
>

Too true. Although one could easily write a little
program to free structure pointers:

PRO Free_Pointers, structure
FOR j=0,N_Tags(structure)-1 DO BEGIN
type = Size(structure.(j), /TName)
IF type EQ 'POINTER' THEN Ptr_Free, structure.(j)
ENDFOR
END

Extra credit for making this recursive. :-)

> Of course, if you need to shorten or lengthen this later, you have to
> remember to dispose of the pointer that you made AFTER you make the new
> one.

Not really. The nice thing about IDL pointers is that
IDL will take care of all the memory manipulation
for you. You don't have to worry about it at all.

> temp = myStruct.array1
> myStruct.array1 = ptr_new( (*myStruct.array1)[0:1024] )
> ptr_free, temp

This really becomes nothing more than this:

*myStruct.array1 = (*myStruct.array1)[0:1024]

There is no need to free the old pointer, make
a new one etc. Pointers are like IDL variables
in this respect. They *always* point to the
current thing you have pointed them too.

> It's sometimes a lot of work to use pointers, but they do exactly what
> you describe you want to.

If by "a lot of work" you mean you have to use
more parentheses than normal, I would agree with
you. Sometimes that syntax drives me crazy! But
the benefits you gain far exceed the cost.

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: IDL and Beowolf ?
Next Topic: Re: polar contour plots

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

Current Time: Wed Oct 08 18:44:26 PDT 2025

Total time taken to generate the page: 0.00395 seconds