Why does std :: list have a maximum size?

If it std::list's a linked list, then why is there a limit on the number of items you have? Each element is a link to a new node, and there is no limit to the number of pointers you can have.

+4
source share
3 answers

If it std::list's a linked list, then why is there a limit on the number of items you can have?

Since the function max_size()is required for all standard containers.

Each element is a link to a new node, and there is no limit to the number of pointers you can have.

, : size_type, - . , .

+6

,

, , . , 64 , max_size() 2 64 -1. , node 1 .

+3

, :

23.2.1 Table 96 — Container requirements . 747 N4296:

a.max_size(); size_type; distance(begin(),end())

, , , ++ . , , ( API). , , , API, , .

However, technically, in any case, there is an upper bound, so it is recommended to use it in such cases. Oddly enough, it is almost impossible to reach the limit that you get from std::list::max_size()(i.e. you run OOM), but alone theoretical infinity.

+1
source

All Articles