# Allocate vs. SetNumberOfPoints

**URL:** https://discourse.vtk.org/t/allocate-vs-setnumberofpoints/4278
**Category:** Support
**Created:** [September 22, 2020, 5:33pm UTC](https://discourse.vtk.org/t/allocate-vs-setnumberofpoints/4278 "2020-09-22T17:33:48Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![RonRahaman](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ronrahaman/32/2350_2.png) [@RonRahaman](https://discourse.vtk.org/u/RonRahaman)
#### Post date: [September 22, 2020, 5:33pm UTC](https://discourse.vtk.org/t/allocate-vs-setnumberofpoints/4278/1 "2020-09-22T17:33:48Z")

</div>

For `vtkPoints` and other similar objects, when should I use `Allocate` and when should I use `SetNumberOfPoints`?

---

<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: [September 22, 2020, 8:34pm UTC](https://discourse.vtk.org/t/allocate-vs-setnumberofpoints/4278/2 "2020-09-22T20:34:03Z")

</div>

They pretty much do the same stuff. `SetNumberOfPoints` calls `SetNumberOfTuples` who calls `Allocate`. Using `SetNumberOfPoints` is easier to read so I would stick with that.

---

<div class="post-metadata">

### Author: ![Sebastien\_Jourdain](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sebastien_jourdain/32/100_2.png) [@Sebastien\_Jourdain](https://discourse.vtk.org/u/Sebastien_Jourdain)
#### Post date: [September 22, 2020, 9:14pm UTC](https://discourse.vtk.org/t/allocate-vs-setnumberofpoints/4278/3 "2020-09-22T21:14:36Z")

</div>

`Allocate` just allocate the memory but leave the number of points to 0. So after that, you can use the `InsertXXX` methods.

While `SetNumberOfPoints` allocate and set the number of points, so after, you need to call `SetPoint(index, x, y, z)`.

---

<div class="post-metadata">

### Author: ![Ron84](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ron84/32/630_2.png) [@Ron84](https://discourse.vtk.org/u/Ron84)
#### Post date: [September 22, 2020, 10:36pm UTC](https://discourse.vtk.org/t/allocate-vs-setnumberofpoints/4278/4 "2020-09-22T22:36:43Z")

</div>

> [@Sebastien\_Jourdain](#):
>
> `Allocate`

What’s the unit of `a` in `vtkPoints::Allocate(a)` and `vtkPolyData::Allocate(a)` ?

---

<div class="post-metadata">

### Author: ![Sebastien\_Jourdain](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sebastien_jourdain/32/100_2.png) [@Sebastien\_Jourdain](https://discourse.vtk.org/u/Sebastien_Jourdain)
#### Post date: [September 22, 2020, 10:39pm UTC](https://discourse.vtk.org/t/allocate-vs-setnumberofpoints/4278/5 "2020-09-22T22:39:13Z")

</div>

I would assume it is the number of values in the given vtkDataArray.  
So for points you will do `points->Allocate(nbPoints * 3)`.
