met*_*eap 1 ram memory-management large-data-volumes go
我正在使用以下简单的Go代码来分配大小为1024x1024x1024的3D数组:
grid = make([][][]TColor, 1024)
for x = 0; x < 1024; x++ {
grid[x] = make([][]TColor, 1024)
for y = 0; y < 1024; y++ {
grid[x][y] = make([]TColor, 1024)
}
}
Run Code Online (Sandbox Code Playgroud)
TColor结构是一个4分量的float64向量:
type TColor struct { R, G, B, A float64 }
Run Code Online (Sandbox Code Playgroud)
通过分配中途(x = 477和y = ~600ish),最内层的make()调用恐慌... 运行时:内存不足:无法分配65536字节块(17179869184正在使用中)
这可以在较低的网格分辨率下工作,即256³,128³等.现在由于结构的大小是4x4字节,整个网格应该只需要16 GB的内存.我的机器(openSuse 12.1 64bit)具有32 GB的可寻址物理(即非虚拟)内存.为什么Go(weekly.2012-02-22)甚至不能分配一半呢?
小智 5
在 Go 语言当前的实现中,在 64 位 CPU 上,Go 运行时为操作系统保留了 16GB 的虚拟内存。这将 Go 程序使用的总内存限制为 16GB。
\n\n如果您计划在需要大量内存的项目中使用 Go,则需要编辑runtime\xc2\xb7mallocinit文件malloc.goc中的函数并增加变量的值arena_size从 16GB 增加到更大的值(例如 32GB)。编辑完成后,运行
cd $GOROOT/src/pkg/runtime\ngo tool dist install -v\nRun Code Online (Sandbox Code Playgroud)\n\n然后重新编译您的项目。
\n