Maximum size of an array in 32 bits?

后端 未结 2 891
旧时难觅i
旧时难觅i 2020-12-20 13:54

According to the Rust Reference:

The isize type is a signed integer type with the same number of bits as the platform\'s pointer type. Th

2条回答
  •  醉话见心
    2020-12-20 14:46

    Rust uses LLVM as compiler backend. The LLVM instruction for pointer arithmetic (GetElementPtr) takes signed integer offsets and has undefined behavior on overflow, so it is impossible to index into arrays larger than 2GB when targeting a 32-bit platform.

    To avoid undefined behavior, Rust will refuse to allocate more than 2 GB in a single allocation. See Rust issue #18726 for details.

提交回复
热议问题