<div>ok.</div>
<div>And why GetNumberOfPoints() does not work ok?<br><br></div>
<div class="gmail_quote">2010/3/12 David Gobbi <span dir="ltr">&lt;<a href="mailto:david.gobbi@gmail.com">david.gobbi@gmail.com</a>&gt;</span><br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">This thread is full of nonsense.  The reason for the error is in the<br>details of how InsertTuple works. Let&#39;s dissect what happens when you<br>
do this:<br>
<div class="im"><br>points-&gt;InsertPoint(60983688, x, y, z);<br><br></div>First, vtkDataArrayTemplate.txx (which is the actual container) will<br>check to see if it has enough memory to hold 60983688 tuples, and if<br>
not, it will allocate a new array that is the sum of the old size and<br>the new size.  Look at the code for<br>vtkDataArrayTemplate::ResizeAndExtend(vtkIdType sz).  Whenever<br>InsertPoint requires that the array is resized, the new size is always<br>
more than double the previous size.<br><br>The reason VTK does this is that resizing by a factor of two is known<br>to be the most computationally efficient way to grow an array when the<br>final size is unknown.  It is definitely not a memory-efficient way of<br>
doing things, but the VTK designers have, quite correctly, chosen<br>computational efficiency over memory efficiency.<br><br>So, when you are using InsertPoint or InsertNextPoint (or InsertTuple<br>or InsertNextTuple), the array will allocate up to twice as much<br>
memory as you actually need.  And if you call InsertTuple repeatedly,<br>then there will be instances where VTK will temporarily require up to<br>three times as much memory as you actually need, while it is copying<br>from the old array to the newly allocated array as part of the resize<br>
operation.<br><br>You can avoid this by using SetNumberOfPoints() to allocate exactly as<br>much space as you need before you add any points.<br><br>  David<br>
<div>
<div></div>
<div class="h5"><br><br>On Fri, Mar 12, 2010 at 8:06 AM, Bill Chivas &lt;<a href="mailto:noo134@googlemail.com">noo134@googlemail.com</a>&gt; wrote:<br>&gt; Thanks David.<br>&gt; I run it without crashing, too.<br>&gt; So, i think the problem is somewhere else ...<br>
&gt;<br>&gt; Thanks,<br>&gt; Bill<br>&gt;<br>&gt; 2010/3/12 David Doria &lt;<a href="mailto:daviddoria%2Bvtk@gmail.com">daviddoria+vtk@gmail.com</a>&gt;<br>&gt;&gt;<br>&gt;&gt; On Fri, Mar 12, 2010 at 9:36 AM, Bill Chivas &lt;<a href="mailto:noo134@googlemail.com">noo134@googlemail.com</a>&gt;<br>
&gt;&gt; wrote:<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; To David:<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; If it works with only two points, try to put some more (e.g. 10).<br>&gt;&gt;&gt; In mine, it crashes in 3 or 4 points.<br>&gt;&gt;&gt;<br>
&gt;&gt;<br>&gt;&gt; This runs without crashing for me:<br>&gt;&gt; #include &lt;vtkSmartPointer.h&gt;<br>&gt;&gt; #include &lt;vtkPoints.h&gt;<br>&gt;&gt; #include &lt;vtkMath.h&gt;<br>&gt;&gt; int main(int argc, char *argv[])<br>
&gt;&gt; {<br>&gt;&gt;   vtkSmartPointer&lt;vtkPoints&gt; points =<br>&gt;&gt;       vtkSmartPointer&lt;vtkPoints&gt;::New();<br>&gt;&gt;<br>&gt;&gt;   points-&gt;SetNumberOfPoints(61000000);<br>&gt;&gt;<br>&gt;&gt;   int start = 60983588;<br>
&gt;&gt;   for(unsigned int i = 0; i &lt; 100; i++)<br>&gt;&gt;     {<br>&gt;&gt;     points-&gt;InsertPoint(start + i, vtkMath::Random(0.0,1.0),<br>&gt;&gt; vtkMath::Random(0.0,1.0), vtkMath::Random(0.0,1.0));<br>&gt;&gt;     }<br>
&gt;&gt;<br>&gt;&gt;   return EXIT_SUCCESS;<br>&gt;&gt; }<br>&gt;&gt; Thanks,<br>&gt;&gt;<br>&gt;&gt; David<br>&gt;<br></div></div>&gt; _______________________________________________<br>&gt; Powered by <a href="http://www.kitware.com/" target="_blank">www.kitware.com</a><br>
&gt;<br>&gt; Visit other Kitware open-source projects at<br>&gt; <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>&gt;<br>&gt; Please keep messages on-topic and check the VTK FAQ at:<br>
&gt; <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>&gt;<br>&gt; Follow this link to subscribe/unsubscribe:<br>&gt; <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
&gt;<br>&gt;<br></blockquote></div><br>