# Data Structures that can hold TH1F object

**URL:** <https://root-forum.cern.ch/t/data-structures-that-can-hold-th1f-object/34446>\
**Category:** Newbie\
**Created:** [June 5, 2019, 6:58pm UTC](https://root-forum.cern.ch/t/data-structures-that-can-hold-th1f-object/34446 "2019-06-05T18:58:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Juan\_Sanchez](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@Juan\_Sanchez](https://root-forum.cern.ch/u/Juan_Sanchez)\
**Post date:** [June 5, 2019, 6:58pm UTC](https://root-forum.cern.ch/t/data-structures-that-can-hold-th1f-object/34446/1 "2019-06-05T18:58:55Z")

</div>

Hello,

It’s that I have been storing different histograms objects in a vector and an array but I always end up getting a seg faults when I try to pass a property of the histogram object to any ROOT function. Is there a useful data structure I can use for this? If not is there any method I can do to get around this?

Best,

-Juan

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [June 5, 2019, 7:31pm UTC](https://root-forum.cern.ch/t/data-structures-that-can-hold-th1f-object/34446/2 "2019-06-05T19:31:58Z")

</div>

Hi Juan,

what are you actually doing? Can you post the code to reproduce a problem?

Cheers,  
D

---

<div class="post-metadata">

**Author:** ![Juan\_Sanchez](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@Juan\_Sanchez](https://root-forum.cern.ch/u/Juan_Sanchez)\
**Post date:** [June 5, 2019, 9:58pm UTC](https://root-forum.cern.ch/t/data-structures-that-can-hold-th1f-object/34446/3 "2019-06-05T21:58:42Z")

</div>

Sorry I am not authorized to post the exact code but the situation is the following:

```auto
TH1F hist[] = {

new TH1F("hist", "", 1, 2, 3)

};

```

Or if I do:

```auto
vector<TH1F> hist = {

new TH1F("hist", "", 1, 2, 3)

}

```

And for example I call:

```auto
hist[0]->Fill(10);

```

This would cause a seg fault and it is the same for every function I call from the class TH1F.

I’ve also tried to initialize the objects outside of the array and vector and then place the pointer object inside them but it brings up the same situation.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [June 5, 2019, 10:50pm UTC](https://root-forum.cern.ch/t/data-structures-that-can-hold-th1f-object/34446/4 "2019-06-05T22:50:31Z")

</div>

`TH1F *hist[]`  
`vector<TH1F*> hist`

---

<div class="post-metadata">

**Author:** ![Juan\_Sanchez](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@Juan\_Sanchez](https://root-forum.cern.ch/u/Juan_Sanchez)\
**Post date:** [June 6, 2019, 5:46pm UTC](https://root-forum.cern.ch/t/data-structures-that-can-hold-th1f-object/34446/5 "2019-06-06T17:46:20Z")

</div>

And how would you delete the memory?

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [June 12, 2019, 6:40pm UTC](https://root-forum.cern.ch/t/data-structures-that-can-hold-th1f-object/34446/6 "2019-06-12T18:40:19Z")

</div>

Loop over the container and call delete on the elements.
