<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 22, 2016 at 9:47 AM, David Lonie <span dir="ltr"><<a href="mailto:david.lonie@kitware.com" target="_blank">david.lonie@kitware.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Fri, Aug 19, 2016 at 2:42 PM, Roberto De Leo<br>
<<a href="mailto:roberto.deleo@howard.edu">roberto.deleo@howard.edu</a>> wrote:<br>
> <--- Example: 1-dim array of N pointers to vtkPolyData<br>
><br>
> vtkPolyData *p[N];<br>
>  for( int i=0; i<N; i++ )<br>
>     p[i] = vtkPolyData::New()<br>
<br>
</span>This looks good. Just be sure to have a similar loop somewhere that<br>
calls p[i]->Delete() to clean these up when you're done using them.<br>
<span class=""><br>
> ----------------><br>
><br>
> <--- Example: 2-dim array of NxM pointers to vtkPolyData<br>
><br>
> vtkPolyData ***p = new vtkPolyData** [N];<br>
> for( int i=0; i<N; i++ ){<br>
>    p[i] = new vtkPolyData* [M];<br>
>    for( int j=0; j<M; j++ )<br>
>        p[i][j] = vtkPolyData::New();<br>
> }<br>
<br>
</span>I think you'd be better off with something like<br>
<br>
vtkPolyData *p[N][M];<br>
  for (... i to N ...)<br>
    for (...j to M...)<br>
<span class="">      p[i][j] = vtkPolyData::New();<br>
<br>
</span>This way you don't have to deal with allocating/freeing the N arrays<br>
of size M, and you'll actually get a contiguous block of vtkPolyData*<br>
pointers. (The code you posted actually allocates an array of N<br>
pointers to non-contiguous arrays of vtkPolyData*[M], rather than a<br>
single block of NxM vtkPolyData*).<br></blockquote><div><br></div><div>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.<br><br></div><div>Like this:<br></div><div>  vtkSmartPointer<vtkPolyData> p[N][M];<br></div><div>  for (... i to N ...)<br></div><div>    for (... j to M ...)<br></div><div>      p[i][j] = vtkSmartPointer<vtkPolyData>::New(); <br><br></div><div>or:<br></div><div>  vtkNew<vtkPolyData> p[N][M];  // vtkNew's constructor does the allocation, so no need for an allocation loop<br><br></div><div>HTH,<br></div><div>Shawn<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
HTH,<br>
Dave<br>
<div class="HOEnZb"><div class="h5">______________________________<wbr>_________________<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/<wbr>opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" rel="noreferrer" target="_blank">http://www.vtk.org/Wiki/VTK_<wbr>FAQ</a><br>
<br>
Search the list archives at: <a href="http://markmail.org/search/?q=vtkusers" rel="noreferrer" target="_blank">http://markmail.org/search/?q=<wbr>vtkusers</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/vtkusers" rel="noreferrer" target="_blank">http://public.kitware.com/<wbr>mailman/listinfo/vtkusers</a><br>
</div></div></blockquote></div><br></div></div>