[vtk-developers] Why is GetRange double* even for non double arrays?

David Gobbi david.gobbi at gmail.com
Mon May 17 09:59:27 EDT 2010


On Mon, May 17, 2010 at 7:51 AM, David Doria <daviddoria+vtk at gmail.com> wrote:
>
> Ok. How does this look? If it's ok, care to commit it?
>
>  void GetValueRange(int range[2])
>  {
>    double r[2];
>    this->GetRange(r);
>    range[0] = static_cast<int>(r[0]);
>    range[1] = static_cast<int>(r[1]);
>  }
>
>  int* GetValueRange()
>  {
>    double r[2];
>    this->GetRange(r);
>    int* range = new int[2];
>    this->GetValueRange(range);
>    return range;
>  }

The second one causes a memory leak.  You would need to store the
range in an ivar:

int *GetValueRange() { this->GetValueRange(this->ValueRange); return
this->ValueRange; }

I wouldn't commit something that does this only for vtkIntArray.  For
consistency, it would have to do the same for all the typed arrays.

  David



More information about the vtk-developers mailing list