Go: how to convert unsafe.Pointer into pointer to array with unknown length?
<p>I am trying to write a Go program which uses <code>mmap</code> to map a very large file containing <code>float32</code> values into memory.  Here is my attempt (inspired by a <a href="https://stackoverflow.com/questions/9203526/mapping-an-array-to-a-file-via-mmap-in-go">previous answer</a>, error handling omitted for brevity):</p>

<pre><code>package main

import (
    "fmt"
    "os"
    "syscall"
    "unsafe"
)

func main() {
    fileName := "test.dat"
    info, _ := os.Stat(fileName)
    fileSize := info.Size()
    n := int(fileSize / 4)

    mapFile, _ := os.Open(fileName)
    defer mapFile.Close()
    mmap, _ := syscall.Mmap(int(mapFile.Fd()), 0, int(fileSize),
        syscall.PROT_READ, syscall.MAP_SHARED)
    defer syscall.Munmap(mmap)
    mapArray := (*[n]float32)(unsafe.Pointer(&amp;mmap[0]))

    for i := 0; i &lt; n; i++ {
        fmt.Println(mapArray[i])
    }
}
</code></pre>

<p>This fails with the following error message:</p>

<pre><code>./main.go:21: non-constant array bound n
</code></pre>

<p>Since <code>n</code> is determined by the length of the file (not known at compile time), I cannot replace <code>n</code> with a constant value in the cast.  How do I convert <code>mmap</code> into an array (or slice) of <code>float32</code> values?</p>