<分区>
我可以在 Go、Java 和 C# 中声明的数组的最大长度是多少?它与运行时的最大内存有关吗?或者他们有标准吗?
<分区>
我可以在 Go、Java 和 C# 中声明的数组的最大长度是多少?它与运行时的最大内存有关吗?或者他们有标准吗?
最佳答案
The Go Programming Language Specification
An array is a numbered sequence of elements of a single type, called the element type. The number of elements is called the length and is never negative.
The length is part of the array's type; it must evaluate to a non-negative constant representable by a value of type
int
.A numeric type represents sets of integer or floating-point values.
There is a set of predeclared numeric types with implementation-specific sizes:
uint the set of all unsigned integers, either 32 or 64 bits int the set of all signed integers, same size as uint
Go数组长度是int
类型的值,是32位或64位有符号整数,取决于编译架构(GOARCH),例如386或amd64。它还受任何硬件或操作系统内存大小限制。
package main
import (
"fmt"
"runtime"
"strconv"
)
func main() {
fmt.Println("int is", strconv.IntSize, "bits on", runtime.GOARCH)
}
输出:
int is 64 bits on amd64
关于java - Go、Java 和 C# 中数组的最大长度是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26622422/