[vtkusers] Re: Memory Issues... (Easier to read version !)

Jeremy Winston jbw at ieee.org
Thu Sep 18 10:16:45 EDT 2003


tutu lamotte wrote:
> [...]
> The way this vtkIdTypeArray::ResizeAndExtend function
> works seams to be on a recursive pattern where the
> memory allocation size is not determined based on the
> need but by the double of the previously allocated
> size.

tutu,
   That's not what the code (from, e.g., Common/vtkLongArray.cxx
in the vtk 4.2.2 distro, file Rev 1.34; code is the same in all
the Common/vtk*Array.cxx files) says:

   long *vtkLongArray::ResizeAndExtend(const vtkIdType sz)
   {
     long *newArray;
     vtkIdType newSize;

     if ( sz > this->Size )
       newSize = this->Size + sz;
     else if (sz == this->Size)
       return this->Array;
     else
       newSize = sz;
     ...

(brackets stripped to save space).  It looks to me like it adds
the requested size to the current size when the requested size
is bigger than the current size.  Seems like a reasonable
approach to me, esp. for a method called "ResizeAndExtend."

If you don't like it, just rewrite the code to something like

     if ( sz > this->Size )
       newSize = sz + 1;

(or whatever you want), and recompile.

HTH,
-Jeremy





More information about the vtkusers mailing list