douda5227 2012-04-07 01:15
浏览 41
已采纳

如何在Go中分配16GB内存?

I'm using the following simple Go code to allocate a 3D array of size 1024x1024x1024:

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)
    }
}

That TColor struct is a 4-component float64 vector:

type TColor struct { R, G, B, A float64 }

Halfway (x=477 and y=~600ish) through the allocation, the inner-most make() call panics with... runtime: out of memory: cannot allocate 65536-byte block (17179869184 in use)

This works fine with lower grid resolutions, ie 256³, 128³ etc. Now since the size of the struct is 4x4 bytes, that whole grid should require exactly 16 GB of memory. My machine (openSuse 12.1 64bit) has 32 GB of addressable physical (ie not-virtual) memory. Why can Go (weekly.2012-02-22) not allocate even half of this?

  • 写回答

2条回答 默认 最新

  • dongyingla8668 2012-04-07 01:32
    关注

    The struct has 4x8 bytes, not 4x4.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示