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

Home » Public Forums » archive » Re: Creating pointer in 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: Creating pointer in structure [message #27749 is a reply to message #27745] Thu, 01 November 2001 07:07 Go to previous messageGo to previous message
Paul van Delst is currently offline  Paul van Delst
Messages: 364
Registered: March 1997
Senior Member
"K. Bowman" wrote:
>
> If I need to define a structure containing a pointer before I know the
> characteristics of the associated heap variable, which of the following
> is preferable? Does it make any difference, or is it simply a matter
> of programming taste?

This is an interesting question.

My personal opinion is that it's a little bit of taste, but more how you design the code.
Choosing which method might depend on how you use the result of PTR_VALID():

IDL> a = {point: PTR_NEW()}
IDL> print, ptr_valid(a.point)
0
IDL> b = {point: PTR_NEW(/ALLOCATE_HEAP)}
IDL> print, ptr_valid(b.point)
1

I prefer the former option because the PTR_VALID() result tells me that the pointer is
definitely not associated with a target (and I like to start with everything nullified). The
second does not without some further checking. This may or may not be an issue in your
initialisation or cleanup routines.

But I think either is fine as long as you're consistent (or not... :o) IDL is more forgiving
than most when freeing a disassociated pointer:

IDL> ptr_free,a.point
IDL> ptr_free,b.point
IDL> print, ptr_valid(a.point)
0
IDL> print, ptr_valid(b.point)
0

My only other experience with pointers is in Fortran 90 where the initial status of a pointer
is undefined and testing the status of an undefined pointer is an error - i.e. you have to
explicitly nullify or allocate the pointer before you can test its status (fortunately, Fortran
95 introduced the ability to nullify pointers when they're declared.)

paulv

>
> For example:
>
> a = {point: PTR_NEW()} ;Create struct w/ null pointer
> ... figure out what n is
> a.point = PTR_NEW(FINDGEN(n)) ;Replace null pointer
>
> or
>
> b = {point: PTR_NEW(/ALLOCATE_HEAP)} ;Create struct w/ pointer->undef
> ... figure out what n is
> *b.point = FINDGEN(n) ;Define heap var
>
> Thanks, Ken

--
Paul van Delst Religious and cultural
CIMSS @ NOAA/NCEP purity is a fundamentalist
Ph: (301)763-8000 x7274 fantasy
Fax:(301)763-8545 V.S.Naipaul
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: gif license
Next Topic: Re: DLM problem when returning an array of structures ...

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

Current Time: Fri Oct 10 03:42:27 PDT 2025

Total time taken to generate the page: 1.59823 seconds