英文:
How do you Mmap() a file bigger than 2GB in Go?
问题
syscall.Mmap()调用需要一个int类型的长度参数,这个参数只能支持2GB大小的文件。那么如何映射一个更大的文件呢?
注意:我使用的是64位系统,所以地址空间不是问题。
英文:
The syscall.Mmap() call takes a length argument of type int, which is only good for 2GB. How do I mmap a bigger file then?
Note: 64-bit system, so address space is not a problem.
答案1
得分: 4
在http://golang.org/src/pkg/syscall/syscall_unix.go中查看mmapper上的Mmap方法。您应该能够复制该代码并根据需要进行调整。
当然,您将无法将mmap映射到[]byte,因为切片长度被定义为“int”(目前在所有地方都是32位)。您可以将mmap映射到更大的元素类型(例如[]int32),或者只是操作指向内存的指针,但它不会是syscall.Mmap的即插即用替代品。
英文:
Look in http://golang.org/src/pkg/syscall/syscall_unix.go at the Mmap method on mmapper. You should be able to copy that code and adapt it as required.
Of course you won't be able to mmap to a []byte, since slice lengths are defined to be "int" (which is 32-bit everywhere at the moment). You could mmap to a larger element type (e.g. []int32), or just muck with the pointer to the memory, but it won't be a drop-in replacement to syscall.Mmap.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论