# Same API returned pointer pointed to diffent array location after printing.

**URL:** https://discourse.vtk.org/t/same-api-returned-pointer-pointed-to-diffent-array-location-after-printing/10284
**Category:** Support
**Created:** [December 21, 2022, 10:11am UTC](https://discourse.vtk.org/t/same-api-returned-pointer-pointed-to-diffent-array-location-after-printing/10284 "2022-12-21T10:11:52Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![AlexLuya](https://discourse.vtk.org/user_avatar/discourse.vtk.org/alexluya/32/4036_2.png) [@AlexLuya](https://discourse.vtk.org/u/AlexLuya)
#### Post date: [December 21, 2022, 10:11am UTC](https://discourse.vtk.org/t/same-api-returned-pointer-pointed-to-diffent-array-location-after-printing/10284/1 "2022-12-21T10:11:52Z")

</div>

Hello,I have a code piece like blew to print same returned vtkDataArray twice:

```auto
	//get the normal of the representative cell
	auto normal = obj->cellNormals()->GetTuple(reprenstiveCell.id);

	std::cout << "Repre Cell Normals ---------- " << normal[0] << " " << normal[1] << " " << normal[3] << std::endl;

	for (int i = 0; i < obj->cellNormals()->GetNumberOfTuples(); i++)
	{
		auto n = obj->cellNormals()->GetTuple(i);
	}
	std::cout << "Repre Cell Normals ---------- " << normal[0] << " " << normal[1] << " " << normal[3] << std::endl;

```

And the printing result likes this:

 ![Workspace 1_1562](https://discourse.vtk.org/uploads/default/original/2X/7/75a13a638df16586714c5e107c3acddf7faef369.png)

As you can see,I have an item pointer which is returned by vtkDataArray-\>GetTuple(idx),in the first printing,it pointed to the “10st” item,after some operations like this:

```auto
	for (int i = 0; i < obj->cellNormals()->GetNumberOfTuples(); i++)
	{
		auto n = obj->cellNormals()->GetTuple(i);
	}

```

It points to “11th”,why would this happen? How to use the API returned pointer properly?

---

<div class="post-metadata">

### Author: ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)
#### Post date: [December 21, 2022, 11:25am UTC](https://discourse.vtk.org/t/same-api-returned-pointer-pointed-to-diffent-array-location-after-printing/10284/2 "2022-12-21T11:25:52Z")

</div>

Methods like “n = obj-\>cellNormals()-\>GetTuple(i);” return temporary pointers to data, and are not thread-safe. They are holdovers from decades ago which, while convenient at times, are a dangerous programming practice and to be discouraged. Use alternative methods like “-\>GetTuple(i,n)” which copy data into n.
