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 #21663 is a reply to message #21614] Wed, 06 September 2000 08:13 Go to previous messageGo to previous message
Martin Schultz is currently offline  Martin Schultz
Messages: 515
Registered: August 1997
Senior Member
David Fanning wrote:
>
> Martin Schultz (martin.schultz@dkrz.de) writes:
>
>> Only if you want
>> to replace the data in a structure element, then you need to free
>> the pointer beforehand:
>>
>> ;; Replace data of first structure
>> IF Ptr_Valid(periodcube.freq) THEN Ptr_Free,
>> periodcube.freq
>> periodcube.freq = Ptr_New( DIndgen(200)*0.1 )
>
> Actually, as I've been trying to point out for
> months now to no avail, it is NOT necessary to
> free the pointer in this instance. IDL *takes
> care of the memory management for you*. :-)
>
> IF Ptr_Valid(periodcube.freq) THEN $
> *periodcube.freq = newThingy
>
> Cheers,
>
> David
>
> P.S. I'm sure Martin knows this. He is just being
> thorough. A trait I have noticed among Germans. :-)

Actually, I didn't know! Well, I've heard this before, but I never
believed it would be that easy. Maybe I am just old-fashioned, but I
always feel like an equilibrist with no safety net if I replace the
contents of a pointer before actually deallocationg the memory it
occupies. And I think I will stick to this habit if only for
compatibility reasons with FORTRAN. Just imagine I would allow our
models to deallocate memory automatically - ain't never gonna happen I
fear...

The second motive for doing it my way is that you will need to have
two statements anyhow. In your example: what happens if the pointer is
not valid? Well, then you need to allocate memory for it, so you
write:

IF Ptr_Valid(periodcube[0].freq) THEN $
*periodcube[0].freq = newThingy $
ELSE $

periodcube[0].freq = Ptr_New(newthingy)

The only reason to do this that I could accept without further
quirking is if you tell me there is a lot of penalty if you manually
deallocate and reallocate the memory instead of letting IDL do it.
Haven't tested, but I would doubt that it makes a big difference.

Cheers,
Martin


--
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[
[[ Dr. Martin Schultz Max-Planck-Institut fuer Meteorologie [[
[[ Bundesstr. 55, 20146 Hamburg [[
[[ phone: +49 40 41173-308 [[
[[ fax: +49 40 41173-298 [[
[[ martin.schultz@dkrz.de [[
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[
[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: Fri Oct 10 08:40:54 PDT 2025

Total time taken to generate the page: 0.87641 seconds