搜尋

首頁  >  問答  >  主體

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.

迷茫迷茫2786 天前866

全部回覆(1)我來回復

  • 迷茫

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

    查了 DevDocs, 它在 std::vector::max_size 條目上如此定義 max_size:

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

    然而 Notes 卻提到:

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

    所以雖說軟體上的max_size 只受限於操作系統或庫實現,然而運行時容器所能容納的元素數量卻可能由於硬體上的內存空間過小,而小於max_size.

    回覆
    0
  • 取消回覆