Maximum size of array

I need to store 5649576 values in an array.
Root terminated abruptly when I run it, but I have managed to isolate the problem and it has to do with the declaration of the array:

ULong64_t Storage[5649576];

Is there a maximum size for an array?

I would probably need a smaller size anyway, but I don’t know how many entries it will have. Is there a way of not declaring the size of an array from the start, but just “adding” entries? Something similar to pushback for a vector in C++.

Why not just use a vector then?

You can not change the size of arrays, but you can make a larger one then copy the old one’s content into the new one as follows:

//Make storage 100 items
ULong64_t *storage;
Int_t numEntries = 100;
storage = new ULong64_t[numEntries];
//Do something with storage
//Need a bigger storage
Int_t newNumEntries = 200;
ULong64_t *newStorage = new ULong64_t[newNumEntires];
mempy(newStorage,storage,numEntries*sizeof(storage[0]));
delete storage;
storage = newStorage;
//Do something with storage
delete storage;

Can we use, in Root, vectors with the “pushback” feature like in C++?

Hi,

yes, in general, not only in the context of ROOT, arrays have a maximum size.
And yes, you can use std::vectors.

Cheers,
Danilo