这是对文件的尝试mmap
并写入单个字节:
package main
import (
"fmt"
"os"
"syscall"
)
func main() {
file, _ := os.Open("/tmp/data")
mmap, _ := syscall.Mmap(int(file.Fd()), 0, 100, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_SHARED)
fmt.Printf("cap is %d", cap(mmap))
mmap[0] = 0
syscall.Munmap(mmap)
}
尽管长度设置为 100,但mmap
容量始终为 0。系统调用出了什么问题?