Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are two limits, both not enforced by C++ but rather by the hardware.</p> <p>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 <code>std::size_t</code> can take. This data type should always be the largest integer type of a system.</p> <p>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 <code>vector&lt;int&gt;</code> of a given size <em>n</em> typically takes about four times as much memory as an array of type <code>vector&lt;char&gt;</code> (minus a small constant value). Therefore, a <code>vector&lt;char&gt;</code> may contain more items than a <code>vector&lt;int&gt;</code> before memory is full. The same counts for the native C-style arrays <code>int[]</code> and <code>char[]</code>.</p> <p>Additionally, this upper limit may be influenced by the type of <code>allocator</code> used to construct the <code>vector</code> because an <code>allocator</code> 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.</p> <p>Apart from that, C++ doesn't enforce any limits.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload