Max value slice

I've read there's an max value/ length/ size for an vector it depends on the system and the size of usize but is there an max/length/size value for a slice?

I'm not 100% sure what you mean, but here is the standard library documentation for slice. You can look through it and see if you can find something that you can use.

usize is the pointer size of the machine. With it you can address all the theoretical addressable space of your machine's memory. For example on a 64 bit machine, theoretically you'll be able to index up to 264. In practice computers don't have that much memory (and don't actually use 64 bit address lines).

I don't know if slices in Rust have a particular specified maximum length, and, like Vec, it's also limited by how much you can address. So usize. Unless your T is one bit sized, you'll run out of memory before you reach the maximum length.

Actually, Vec can have up to isize::MAX bytes.
See also What is the maximum length of a vector?.

1 Like

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.