[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie Questions



Geoff Herbynchuk wrote:

> And, if we do:
> 
> bar_ptr = ptr_new(bar, /no_copy)
> 
> bar_ptr will now just point to the memory location where bar is stored
> (not copy it to a heap location)?  We can then update the bar, or the
> components of bar(if bar is a structure) by dereferencing bar_ptr,
> right?

Wrong :(  With /no_copy, bar becomes undefined, because its value is
taken away and being attached directly to bar_ptr.


> For example:
> 
> *bar_ptr.name = 'Geoff'

Caution, this would be (*bar_ptr).name, because bar_ptr is the pointer,
not bar_ptr.name.


> Thanks for everyone's help.  I've only worked with pointers in
> C/C++ before, and I'm getting the impression that these don't work
> exactly the same way.  =)

Correct. In C, they are real pointers to a memory location. In IDL, they
are just a heap variable. Tricks like p=&a, *p=5 to set a to 5 will not
work in IDL.
You can, however, set bar2_ptr = bar_ptr, and now at least these two
point to the same value, and *bar2_ptr = 0 also sets *bar_ptr to 0.

        Alex
-- 
  Alex Schuster     Wonko@weird.cologne.de          PGP Key available
                    alex@pet.mpin-koeln.mpg.de