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 4×4 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?
The struct has 4×8 bytes, not 4×4.