Huge Memory Offsets and std::pointer::add

I was reading the documentation for std::pointer::add and I came upon this section addressing the requirement that the offset must be contained in an isize:

Most platforms fundamentally can’t even construct such an allocation. For instance, no known 64-bit platform can ever serve a request for 2^63 bytes due to page-table limitations or splitting the address space. However, some 32-bit and 16-bit platforms may successfully serve a request for more than isize::MAX bytes with things like Physical Address Extension. As such, memory acquired directly from allocators or memory mapped files may be too large to handle with this function.

How common are such systems, and are there any particular use case where such systems might be preferred?

I'm writing a (hopefully performant) data structure which requires some pointer operations, and I'm wondering if I should include a check making sure that I don't overflow an isize. Or, is this case so extreme that it probably wouldn't be worth the overhead?

It is possible on pretty much every 32-bit system.

BTW, enforcing sizes below isize::MAX is part of Rust's safety guarantee. If you're creating interfaces that aren't marked unsafe it is your responsibility to always check for this overflow. Rust's std always checks for this.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.