Array resizing

I was sifting through the openfoam reader and stumbled across something that looks to me like legacy code:

// this is necessary due to the strange vtkDataArrayTemplate::Resize()
// implementation when the array size is to be extended
template <typename T1, typename T2>
bool vtkOpenFOAMReaderPrivate::ExtendArray(T1* array, vtkIdType nTuples)
{
  vtkIdType newSize = nTuples * array->GetNumberOfComponents();
  void* ptr = malloc(static_cast<size_t>(newSize * array->GetDataTypeSize()));
  if (ptr == nullptr)
  {
    return false;
  }
  memmove(ptr, array->GetVoidPointer(0), array->GetDataSize() * array->GetDataTypeSize());
  array->SetArray(static_cast<T2*>(ptr), newSize, 0);
  return true;
}

This reminded me of something that I had read in the vtkCellArray class, where the Resize() is now actually ResizeExact().

The header comment for the top-level vtkAbstractArray::Resize method (reformatted in 2016, but probably much older) notes

Increasing the array size may allocate extra memory beyond what was requested.

Which is still a bit vaguely phrased for my liking. If I examine the concrete classes of interest for me (vtkFloatArray, vtkTypeInt32Array etc), they all derive from vtkAOSDataArrayTemplate -> vtkGenericDataArray.

The vtkGenericDataArray::Resize() seems to catch no-op resizing (ie, the size doesn’t change).If the size does increase, it appears to use an exact resizing (line 418 of vtkGenericDataArray.txx), and from what I can follow through to the vtkBuffer level (via the vtkAOSDataArrayTemplate), it does seem to be an exact realloc.

I will not ask the question about why this all so hard to trace what is going on, but instead ask which of these lists are longer?

  • array types where Resize() is exact
  • array types where Resize() uses doubling or some other strategy.

Anyone able to itemize these? (possibly in the headers too).