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

Home » Public Forums » archive » Re: Object Data and pointer assignments
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: Object Data and pointer assignments [message #19318 is a reply to message #19317] Thu, 09 March 2000 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Ben Tupper (tupper@seadas.bigelow.org) writes:

> I am in the middle of wrtting my first object from scratch. Scratch is
> a good word since I'm doing a lot of that on my head. I'm hoping to get
> some advice on organization of data. I need 4 pieces of data (one 2d
> arrays and two structures that vary in size according to the size of the
> arrays) plus six keywords that I need to get/set. Currently, I have
> defined each of the 3 bits of data as null pointers in the BLAH__DEFINE
> procedure.
>
> In the BLAH::INIT function, the user passes one of the two arrays as an
> argument. At that point I reassign one of the pointers to...
>
> Self.InArray = Ptr_New(InArray).
>
> I think I understand why I can reassign the structure field when going
> from a null pointer to a filled pointer. On second thought, I don't
> understand it but I can accept that it works. It's the next step I need
> help on.

The reason you need to use an actual pointer (Ptr_New) here,
is that you *don't* have a pointer from the BLAH__DEFINE
module. What you have done in that module is said that the
*definition* of the InArray field *will be* a pointer. In other
words, the BLAH__DEFINE module only *defines* the object and
its fields, it doesn't assign anything to the self object. This
is what must be done by the INIT method.

> I would like to change the contents of this field later to some other
> value (a differently sized array.) Here's where the ice under me gets
> very very thin and my eyes get misty. In the BLAH::SETPROPERTY method,
> I don't know if I should free this pointer before reassigning (and does
> that leave the structure field undefined?), or if I should simply
> overwrite it as I did in the INIT function. If I reassign the filed
> to a new pointer, what happens to the previously occupied heap space?
> Have I sprung a leak?

To reassign the pointer to something else (after it has been
defined by the INIT method), you simple de-reference the pointer:

*self.InArray = newStruct

You don't leak any memory because IDL is managing this
whole process for you. (Remember, these pointers are
not real pointers in the C sense. They are really
glorified variables in the IDL sense.) This is the
bestest feature of IDL pointers. :-)

If you overwrite the pointer like this:

self.InArray = Ptr_New(newStruct)

you *will* leak memory because now you destroyed the
only reference to that pointer area of memory. You could
do this:

Ptr_Free, self.InArray
self.InArray = Ptr_New(newStruct)

But what is the point, if IDL can do it all for you?

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
Read Message
Read Message
Previous Topic: Re: Q: contour levels from IDL
Next Topic: Re: IDL and Linux on dual processor

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

Current Time: Fri Oct 10 15:17:24 PDT 2025

Total time taken to generate the page: 1.19893 seconds