# vtkAbstractArray::Resize behaviour

**URL:** https://discourse.vtk.org/t/vtkabstractarray-resize-behaviour/7160
**Category:** Support
**Created:** [November 12, 2021, 6:02pm UTC](https://discourse.vtk.org/t/vtkabstractarray-resize-behaviour/7160 "2021-11-12T18:02:53Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![drpeterfranz](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/d/f19dbf/32.png) [@drpeterfranz](https://discourse.vtk.org/u/drpeterfranz)
#### Post date: [November 12, 2021, 6:02pm UTC](https://discourse.vtk.org/t/vtkabstractarray-resize-behaviour/7160/1 "2021-11-12T18:02:53Z")

</div>

The _vtkAbstractArray::Resize()_ method states:

> [@](#):
>
> Resize the array to the requested number of tuples and preserve data.
> 
> Increasing the array size may allocate extra memory beyond what was requested. MaxId will not be modified when increasing array size. Decreasing the array size will trim memory to the requested size and may update MaxId if the valid id range is truncated. Requesting an array size of 0 will free all memory. Returns 1 if resizing succeeded and 0 otherwise.

So indeed, when I resize an array I get

> [@](#):
>
> double\_array-\>Resize(5);  
> vtkIdType double\_tuples = double\_array-\>GetNumberOfTuples(); // yields 0  
> vtkIdType double\_vals = double\_array-\>GetNumberOfValues(); // yields 0

So what should I do if I have an array with existing data which I want to preserve, but create additional space beyond it. After resizing I want _GetNumberOfTuples()_ to return the number to which I have resized the array. So would

> [@](#):
>
> double\_array-\>Resize(5);  
> double\_array-\>SetNumberOfTuples(5);

be the correct way to achieve this?

---

<div class="post-metadata">

### Author: ![Yohann\_Bearzi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/yohann_bearzi/32/671_2.png) [@Yohann\_Bearzi](https://discourse.vtk.org/u/Yohann_Bearzi)
#### Post date: [November 12, 2021, 6:16pm UTC](https://discourse.vtk.org/t/vtkabstractarray-resize-behaviour/7160/2 "2021-11-12T18:16:11Z")

</div>

You’re correct. You need to call `Resize` before calling `SetNumberOfTuples`.

---

<div class="post-metadata">

### Author: ![drpeterfranz](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/d/f19dbf/32.png) [@drpeterfranz](https://discourse.vtk.org/u/drpeterfranz)
#### Post date: [November 12, 2021, 6:17pm UTC](https://discourse.vtk.org/t/vtkabstractarray-resize-behaviour/7160/3 "2021-11-12T18:17:18Z")

</div>

Thanks!
