[vtkusers] vtkDenseArray reference counting?

Jeff Baumes jeff.baumes at kitware.com
Mon Nov 16 12:01:42 EST 2009


On Mon, Nov 16, 2009 at 11:56 AM, David Doria <daviddoria+vtk at gmail.com> wrote:
>> As your code is written now, you are telling the array to store raw
>> pointers; it does not even know that the pointers are vtkObject
>> subclasses, so it does not know it should increment the reference
>> count. The correct way to make this "just work" is to define the
>> storage container as
>>
>> vtkSmartPointer<vtkDenseArray<vtkSmartPointer<vtkRay> > > array = ...
>>
>> Of course you may need to do some trickery for allowing
>> vtkSmartPointer<vtkRay> to be converted to a vtkVariant. Similarly, a
>> nice way to store vtkObject classes in a std::vector (or any other STL
>> storage container) is with:
>>
>> std::vector<vtkSmartPointer<vtkRay> > array;
>> ...
>> array[i] = vtkSmartPointer<vtkRay>::New();
>>
>> This will automatically keep a reference count for each object in the
>> array until the array is destructed.
>>
>> Jeff
>
> I had to add
>
> #include "vtkVariant.h"
>
> and
>
>  operator vtkVariant() const { return vtkVariant(); }
>
> to vtkSmartPointer.h
>
> Jeff, is there anyway you can commit those changes so this will work for
> everyone?
>

We are actually working on a more general solution so that you will
not need to implement this vtkVariant conversion on types used in
vtkArray and subclasses. Basically the Get/SetVariant methods in
vtkArray would be non-functional in general, but would work if you
used a supported basic type.

Jeff



More information about the vtkusers mailing list