You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It isn't easy to make a slice with len > maxint.
This doesn't work:
var x [1<<63]struct{}
gives array bound is too large.
make([]struct{}, 1<<63) gives len argument too large in make([]struct {}).
And this code:
x := []struct{}{struct{}{}}
for {
println(len(x))
x = append(x, x...)
}
eventually dies with panic: runtime error: growslice: cap out of range.
I'm out of ideas for how to actually manufacture a slice with a length bigger than maxint (without using unsafe). And I'm pretty sure that's by design.
The language does not permit the number of elements in a slice to exceed the maximum value of int. (This was one of the main reasons we changed the size of int from 32 bits to 64 bits on 64-bit systems, back in the Go 1.1 release: https://golang.org/doc/go1.1#int).
Currently the
len( )
function returns anint
. Changing it touint
has already been proposed and rejected.Can the documentation clarify what
len( )
returns when the number of items in a slice exceeds the max value of an int?The text was updated successfully, but these errors were encountered: