[vtkusers] Arrays and double arrays of VTK pointers

David Lonie david.lonie at kitware.com
Mon Aug 22 10:54:37 EDT 2016


On Mon, Aug 22, 2016 at 9:55 AM, Shawn Waldon <shawn.waldon at kitware.com> wrote:
> I would use vtkSmartPointer or vtkNew so that you don't have to worry about
> deleting them in a similar loop later.  vtkNew has the advantage that you
> don't even have to write the allocation loop, but you have to call Get() to
> pass it as a pointer to another function.
>
> Like this:
>   vtkSmartPointer<vtkPolyData> p[N][M];
>   for (... i to N ...)
>     for (... j to M ...)
>       p[i][j] = vtkSmartPointer<vtkPolyData>::New();
>
> or:
>   vtkNew<vtkPolyData> p[N][M];  // vtkNew's constructor does the allocation,
> so no need for an allocation loop

Agreed, thanks for pointing that out -- I personally go for vtkNew
whenever possible just because it's so much easier to use. The only
reason to bother with manually allocating the objects is if you really
just need the raw pointers in the arrays for some reason (I'm not sure
if that was a requirement here, but I wanted to point that out just in
case).


More information about the vtkusers mailing list