FiberOptix wrote: As I said, I don't know what length the array will be and I don't want to be inefficient and just initialize a very large array.
"Inefficient" is an interesting word here, because you might have some misconceptions. Allocating a large array is very efficient compared to growing an array incrementally in a loop. So, if you can guess an reasonable upper limit for the size, allocate that (or even twice that!) and then do everything "in place" inside the loop, it will be much more efficient than growing the array with most iterations. Every time you resize an array, a new copy of the array needs to be made in memory, so that can become very expensive in the long run.
For an illustrative example, have a look at code alternatives that remove certain elements from a large array. Using "delete from array" (a resizing operation!) will become exceedingly expensive. Have a look at the post
here. For an array with 500000 elements, it can mean the difference between 60 seconds and 12milliseconds! and for a 10x larger array the difference is estimated to be 100minutes(!!) vs. 120ms, or about the blink of an eye compared to an extended lunch break.
😮 (Please read the entire thread for more specific discussions). Similar rules apply for growing arrays as in your case.
Unless your array will be 100's of megabytes and you run into memory and OS limitations, memory is typically not an issue.