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. The theoretical upper bound on object and array size is the maximumisize
value. This ensures thatisize
can be used to calculate differences between pointers into an object or array and can address every byte within an object along with one byte past the end.
This obviously constrain an array to at most 2G elements on 32 bits system, however what is not clear is whether an array is also constrained to at most 2GB of memory.
In C or C++, you would be able to cast the pointers to the first and one past last elements to char*
and obtain the difference of pointers from those two; effectively limiting the array to 2GB (lest it overflow intptr_t
).
Is an array in 32 bits also limited to 2GB in Rust? Or not?