How long can an array be, and how can I extend that length?

An array's size is only limited to the memory of the machine running the code. If you want to make an array larger you will need to read up on dynamic arrays. If you need storage that can get very large or you need it to grow I would suggest using something from the STL. Perhaps a vector would work for you.

I know about dynamic arrays, but my compiler gives me an error whenever I use an array index above 10000. I need to know how to determine the maximum length of a dynamic array.

It is all dependent on the amount of ram int the system. Are you creating the array using the new operator or are you defining the size at compile time?

Edited 5 Years Ago by NathanOliver: n/a

New operator, and I guess I will refine my question to how can I know if I have created too many elements? ie:

int *test;
int numtest;
test=new int[x];
if (test has overstepped my RAM's capability)
{
//do something
}

Well if you have a array of 100000 doubles it would only need about 8mb of ram so I'm not sure why you wouldn't be able to create an array of 10000 elements unless they use a lot of memory. What is the error that you are getting and what compiler/IDE are you using?

An array's size is only limited to the memory of the machine running the code.

It would be limited to the sizeof(std::size_t) See definition of the new operator

Edited 5 Years Ago by Ancient Dragon: n/a

Well if you have a array of 100000 doubles it would only need about 8mb of ram so I'm not sure why you wouldn't be able to create an array of 10000 elements unless they use a lot of memory. What is the error that you are getting and what compiler/IDE are you using?

Actually, an array 100000 doubles would take less than 1MB (800KB @ 8bytes / double).

This question has already been answered. Start a new discussion instead.