<p>Is there a max length for an array in C++?</p>

<p>Is it a C++ limit or does it depend on my machine? Is it tweakable? Does it depend on the type the array is made of?</p>

<p>Can I break that limit somehow or do I have to search for a better way of storing information? And what should be the simplest way?</p>

<p>What I have to do is storing long long int on an array, I'm working in a Linux environment. My question is: what do I have to do if I need to store an array of N long long integers with N > 10 digits?</p>

<p>I need this because I'm writing some cryptographic algorithm (as for example the p-Pollard) for school, and hit this wall of integers and length of arrays representation.</p>

There are two limits, both not enforced by C++ but rather by the hardware.
The first limit (should never be reached) is set by the restrictions of the size type used to describe an index in the array (and the size thereof). It is given by the maximum value the system's
```
std::size_t
```
can take. This data type is large enough to contain the size in bytes of any object
The other limit is a physical memory limit. The larger your objects in the array are, the sooner this limit is reached because memory is full. For example, a
```
vector<int>
```
of a given size
n
typically takes multiple times as much memory as an array of type
```
vector<char>
```
(minus a small constant value), since
```
int
```
is usually bigger than
```
char
```
. Therefore, a
```
vector<char>
```
may contain more items than a
```
vector<int>
```
before memory is full. The same counts for raw C-style arrays like
```
int[]
```
and
```
char[]
```
.
Additionally, this upper limit may be influenced by the type of
```
allocator
```
used to construct the
```
vector
```
because an
```
allocator
```
is free to manage memory any way it wants. A very odd but nontheless conceivable allocator could pool memory in such a way that identical instances of an object share resources. This way, you could insert a lot of identical objects into a container that would otherwise use up all the available memory.
Apart from that, C++ doesn't enforce any limits.