[vtkusers] Arrays and double arrays of VTK pointers
David Lonie
david.lonie at kitware.com
Mon Aug 22 09:47:34 EDT 2016
On Fri, Aug 19, 2016 at 2:42 PM, Roberto De Leo
<roberto.deleo at howard.edu> wrote:
> <--- Example: 1-dim array of N pointers to vtkPolyData
>
> vtkPolyData *p[N];
> for( int i=0; i<N; i++ )
> p[i] = vtkPolyData::New()
This looks good. Just be sure to have a similar loop somewhere that
calls p[i]->Delete() to clean these up when you're done using them.
> ---------------->
>
> <--- Example: 2-dim array of NxM pointers to vtkPolyData
>
> vtkPolyData ***p = new vtkPolyData** [N];
> for( int i=0; i<N; i++ ){
> p[i] = new vtkPolyData* [M];
> for( int j=0; j<M; j++ )
> p[i][j] = vtkPolyData::New();
> }
I think you'd be better off with something like
vtkPolyData *p[N][M];
for (... i to N ...)
for (...j to M...)
p[i][j] = vtkPolyData::New();
This way you don't have to deal with allocating/freeing the N arrays
of size M, and you'll actually get a contiguous block of vtkPolyData*
pointers. (The code you posted actually allocates an array of N
pointers to non-contiguous arrays of vtkPolyData*[M], rather than a
single block of NxM vtkPolyData*).
HTH,
Dave
More information about the vtkusers
mailing list