Take the 2-minute tour ×

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.

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

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.

share|improve this answer
Even if I map to []int64, it will only handle max 16GB files, right? Still quite limited on modern 64-bit platforms. –  Rio Jul 24 '12 at 12:06
That's 16GB at a time. You can rebuild the slice header as often as you want without having to re-mmap. –  dsymonds Jul 26 '12 at 6:50
That's disappointing. Slices are supposed to be a better replacement for pointer arithmetic so they eliminated pointer arithmetic (except with the "unsafe" package), but slices are hamstrung! I would think that the slice index type should be uintptr with automatic conversion to/from other integer types. –  Matt Jul 27 '12 at 18:51
go1.1 will have 64-bit ints on 64-bit platforms, which will largely solve this. –  dsymonds Sep 28 '12 at 5:29
Note that this is unix only. Go in Windows has a different api for memory mapped files. –  kristianp Jan 12 '13 at 5:16
add comment

Your Answer


