C++ vector max_size();

前端 未结 3 1220

On 32 bit System.

  1. std::vector::max_size() returns 232-1, size of char — 1 byte
  2. std::vecto
3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-31 05:39

    max_size() returns

    the maximum potential size the vector could reach due to system or library implementation limitations.

    so I suppose that the maximum value is implementation dependent. On my machine the following code

    std::vector v;
    cout << v.max_size();
    

    produces output:

    4611686018427387903 // built as 64-bit target
    1073741823 // built as 32-bit target
    

    so the formula 2^(64-size(type))-1 looks correct for that case as well.

提交回复
热议问题