[vtkusers] vtkSmartPointer usage question

Alex Malyushytskyy alexmalvtk at gmail.com
Thu Nov 5 17:50:25 EST 2009


David,

It looks like tutorial at
http://www.vtk.org/Wiki/Smart_Pointers
is the most detailed explanation I seen by now.

The only thing is  not clear  for me is how to force smartpointer to
release the data.

I may be missing the obvious, but at least I could not get it  from
documentation or class description.

"  // Description:
  // Assign object to reference.  This removes any reference to an old
  // object.
  vtkSmartPointer& operator=(T* r)"

What happens to the old reference?
I can assume that reference count will be decreased. Will it or not?
Would pointer be deleted if its reference count get to 0 when de -referenced ?
Logically I would answer positive on both questions, but that are my
assumptions.
I can try to see if they are correct by testing, but I would prefer to
see it somewhere in the documentation, so you can be sure how code
supposed to work.


For example stl auto_ptr  class provides "release" member, which
replaces the stored pointer  with a null pointer and returns the
previously stored pointer.

Basically this means that you get a normal pointer which you can
handle yourself.
And auto_ptr which can be used for other purposes (usually associated
with different raw pointer).

Such functionality is useful when you have smart pointers as class
members and need to update data due to some changes.

As for me as soon "How to release" is clarified, there is no need in
"Putting an
Existing Object into a Smart Pointer", cause this assumes two
operations: release and assign,
and "assign" is already covered in your guide.


Thanks for a great work,

  Alex


>>
>>Alex, I made you a slot to say something about this "Putting an
>>Existing Object into a Smart Pointer" (I'm not sure what else to call
>>it).
>>
>>Can anyone verify what is there makes sense / add to it? Surely I am
>>just touching on the very basics and maybe missing some of the
>>idea/power of them...
>>
>>Thanks,
>>
>>David



More information about the vtkusers mailing list