TObjArray and RemoveAt(n)

Hello Rooters
I use ROOT 5.34/04 on Centos 6
In Root when i execute theses lines :

TObjArray toa;
TH1I th0(“th0”,“th0”,0,10,10);
TH1I th1(“th1”,“th1”,0,10,10);
TH1I th2(“th2”,“th2”,0,10,10);
TH1I th3(“th3”,“th3”,0,10,10);
printf (“Last = %d\n”,toa.GetLast());
toa.RemoveAt(3); // in this case i remove the last
printf (“Last = %d\n”,toa.GetLast());
toa.RemoveAt(1);// in this case i remove in middle of array
printf (“Last = %d\n”,toa.GetLast());

Afer the first removeAt the GetLast decrease but not in seconde case , Why?

Thank a lot for your help


TObjArray does not remove holes after calling RemoveAt(). It only resets the pointer and reduces the overall size if holes at found at the end of the array. This is why removing the last element reduces the size but not if some middle element is removed.

see TObjArray::Compress

Thanks for these clear explanations!