[vtk-developers] RFC: vtkScopedPointer - a new hope?

Marcus D. Hanwell marcus.hanwell at kitware.com
Tue Jan 25 09:28:23 EST 2011


On Mon, Jan 24, 2011 at 11:45 PM, Bill Lorensen <bill.lorensen at gmail.com> wrote:
> I like vtkNew. The adjective Scoped does not add anything since all
> variables declared inside {}'s are scoped, aren't they?
>
They are, but a vtk object rarely gets deleted when the object that
contains it goes out of scope. This happens with vtkSmartPointer, and
possibly with this new container. I was offering something a little
more explicit as I know the VTK convention is to attempt to
self-document with the class names.

It behaves almost exactly like a scoped pointer, apart from the fact
that all VTK objects are reference counted, and so we never use the
delete operator on them and so it is trivial to take ownership (as Qt
does in their scoped pointer). I thought vtkScopedNew might offer that
middle ground - I am more about the functionality and avoiding
confusion.

I will of course ensure the new class, whatever its name, is well
documented. I think the widespread use of the VTK create macro shows a
need, and it was disappointing to see it fail to get into VTK 5.6 due
to smart pointer interaction which I saw as a secondary concern at
best.

Marcus



More information about the vtk-developers mailing list