<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"><<a href="mailto:david.gobbi@gmail.com">david.gobbi@gmail.com</a>></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's dissect what happens when you<br>
do this:<br>
<div class="im"><br>points->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 <<a href="mailto:noo134@googlemail.com">noo134@googlemail.com</a>> wrote:<br>> Thanks David.<br>> I run it without crashing, too.<br>> So, i think the problem is somewhere else ...<br>
><br>> Thanks,<br>> Bill<br>><br>> 2010/3/12 David Doria <<a href="mailto:daviddoria%2Bvtk@gmail.com">daviddoria+vtk@gmail.com</a>><br>>><br>>> On Fri, Mar 12, 2010 at 9:36 AM, Bill Chivas <<a href="mailto:noo134@googlemail.com">noo134@googlemail.com</a>><br>
>> wrote:<br>>>><br>>>> To David:<br>>>><br>>>> If it works with only two points, try to put some more (e.g. 10).<br>>>> In mine, it crashes in 3 or 4 points.<br>>>><br>
>><br>>> This runs without crashing for me:<br>>> #include <vtkSmartPointer.h><br>>> #include <vtkPoints.h><br>>> #include <vtkMath.h><br>>> int main(int argc, char *argv[])<br>
>> {<br>>> vtkSmartPointer<vtkPoints> points =<br>>> vtkSmartPointer<vtkPoints>::New();<br>>><br>>> points->SetNumberOfPoints(61000000);<br>>><br>>> int start = 60983588;<br>
>> for(unsigned int i = 0; i < 100; i++)<br>>> {<br>>> points->InsertPoint(start + i, vtkMath::Random(0.0,1.0),<br>>> vtkMath::Random(0.0,1.0), vtkMath::Random(0.0,1.0));<br>>> }<br>
>><br>>> return EXIT_SUCCESS;<br>>> }<br>>> Thanks,<br>>><br>>> David<br>><br></div></div>> _______________________________________________<br>> Powered by <a href="http://www.kitware.com/" target="_blank">www.kitware.com</a><br>
><br>> Visit other Kitware open-source projects at<br>> <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>><br>> Please keep messages on-topic and check the VTK FAQ at:<br>
> <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>><br>> Follow this link to subscribe/unsubscribe:<br>> <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
><br>><br></blockquote></div><br>