<div dir="ltr">Thanks for confirming what I assumed but was not able to fully verify myself!<div><br></div><div>With that first smart pointer I would not have "dared" to go because I would now know whether the output data is already managed by some smart pointer inside the filter. Meaning that the memory would be released once the filter goes out of scope - with the result that the new smart pointer would not really have control of that memory! This is why I felt more "safe" by using one extra data item in my own code.</div><div><br></div><div>But now I am taking your word that this is not going to happen. Actually the memory for the input and output objects seems to be managed by the caller of RequestData() anyway, no need to manage that memory inside the function.</div><div><br></div><div>Regards,</div><div>Cornelis</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-02-02 15:46 GMT+01:00 Utkarsh Ayachit <span dir="ltr"><<a href="mailto:utkarsh.ayachit@kitware.com" target="_blank">utkarsh.ayachit@kitware.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">In general (unless I missed something), it looks fine. A couple of notes:<div><br></div><div>1. You don't need to even shallow copy, you can simply save the output from any of the internal filters (I typically use a vtkSmartPointer to hold on to the reference). e.g.</div><div><br></div><div>  vtkSmartPointer<vtkDataObject> intermediaResult = <span style="font-size:12.8px">filt1</span>->GetOutput();</div><div><br></div><div>2. You can connect fil1 and filt2 in a pipeline too, to avoid keeping the intermediate dataset explicitly:</div><div><br></div><div>   filter2->SetInputConnection(<wbr>filt1->GetOutputPort());</div><div>   filter2->Update();</div><div>   output->ShallowCopy(filter2-><wbr>GetOutput());</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Thu, Feb 2, 2017 at 6:42 AM, Cornelis Bockemühl <span dir="ltr"><<a href="mailto:cornelis.bockemuehl@gmail.com" target="_blank">cornelis.bockemuehl@gmail.com</a><wbr>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr">Dear all,<div><br></div><div>Would the following construct be safe in terms of proper data handling inside a filter or would I generate some "unpredictable results", like data being copied over other data that is still being used?</div><div><br></div><div>My purpose is of course to copy data only if it is absolutely required. And I assume that within the different filters, data are again handled correctly.</div><div><br></div><div>...::RequestData(...)</div><div>{</div><div>  // get input and output</div><div>  vtkPolyData* input0 = vtkPolyData::SafeDownCast(in<wbr>fo->Get(vtkDataObject::DATA_OB<wbr>JECT()));</div><div>  vtkPolyData* output = vtkPolyData::SafeDownCast(...)<wbr>;</div><div>  ...</div><div><br></div><div>  // intermediate data storage</div><div>  vtkSmartPointer<vtkPolyData> intermediateData = vtkSmartPointer<vtkPolyData>::<wbr>New();</div><div><br></div><div>  // first filter</div><div>  vtkSmartPointer<vtkSomeFilter> filt1 = vtkSmartPointer<vtkSomeFilter><wbr>::New();</div><div>  filt1->SetInputData(input0);</div><div>  ...</div><div>  filt1->Update();</div><div>  intermediateData->ShallowCopy(<wbr>filt1->GetOutput());</div><div><br></div><div>  // second filter</div><div>  vtkSmartPointer<vtkSomeOtherFi<wbr>lter> filt2 = vtkSmartPointer<vtkSomeOtherFi<wbr>lter>::New();</div><div>  filt2->SetInputData(intermedia<wbr>teData);</div><div>  ...</div><div>  filt2->Update();</div><div>  intermediateData->ShallowCopy(<wbr>filt2->GetOutput()); // !!! actually replacing the input data...</div><div><br></div><div>  // some more filters in the same way as filt2 - with always reusing intermediateData...</div><div>  ...</div><div><br></div><div>  // return the results</div><div>  output->ShallowCopy(intermedia<wbr>teData);<br></div><div>}</div><div><div><br></div><div>Any comments?</div><div><br></div><div>Of course I could play safe and</div><div><br></div><div>1) replace all "ShallowCopy" with "DeepCopy", and</div><div>2) generate an intermediate data object for each and every filter that I am applying</div><div><br></div><div>but this for sure would blow up my memory enormously!</div><div><br></div><div>Maybe there is also some document that clearly states what is the proper "behaviour" inside filters like that, some kind of "code of conduct" regarding memory management in VTK?</div><div><br></div><div>Thanks for any helpful hints!</div><div><br></div><div>Regards,</div><div>Cornelis</div><span class="m_8364758405971602619HOEnZb"><font color="#888888"><div><br></div>-- <br><div class="m_8364758405971602619m_-7045021852117245839gmail_signature">Cornelis Bockemühl<br>Basel, Schweiz<br></div>
</font></span></div></div>
<br></div></div>______________________________<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/opensou<wbr>rce/opensource.html</a><br>
<br>
Please keep messages on-topic and check the ParaView Wiki at: <a href="http://paraview.org/Wiki/ParaView" rel="noreferrer" target="_blank">http://paraview.org/Wiki/ParaV<wbr>iew</a><br>
<br>
Search the list archives at: <a href="http://markmail.org/search/?q=ParaView" rel="noreferrer" target="_blank">http://markmail.org/search/?q=<wbr>ParaView</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/paraview" rel="noreferrer" target="_blank">http://public.kitware.com/mail<wbr>man/listinfo/paraview</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Cornelis Bockemühl<br>Basel, Schweiz<br></div>
</div>