search

Home  >  Q&A  >  body text

c++ - max_size返回一个大于或等于该类型容器所能容纳的最大元素数的值?

这是c++ primer中讲到容器大小一节时说的一句话,什么叫大于最大值?感觉错的太离谱了吧
英文版如下:
and max_size returns a number that is greater than or equal to the number of elements a container of that type can contain.

迷茫迷茫2785 days ago863

reply all(1)I'll reply

  • 迷茫

    迷茫2017-04-17 12:09:46

    Checked the DevDocs, it is defined as follows on the std::vector::max_size entry max_size:

    Returns the maximum number of elements the container is able to hold due to system or library implementation limitations,...

    However, Notes mentioned:

    This value is typically equal to std::numeric_limits<size_type>::max(), and reflects the theoretical limit on the size of the container. At runtime, the size of the container may be limited to a value smaller than max_size() by the amount of RAM available.

    So although the software max_size is only limited by the operating system or library implementation, the number of elements that the runtime container can hold may be smaller than max_size.<🎜 due to the small memory space on the hardware. >

    reply
    0
  • Cancelreply