Reputation: 653
I want to read a mmap file in golang.
Another process is writing things into it so its size is growing while reading.
I am using
syscall.Mmap(fd int, offset int64, length int, prot int, flags int)
which will return a byte array.
Do I need to keep doing syscall.Mmap
to read the updated mmap? Any better way?
Upvotes: 0
Views: 848
Reputation: 10000
syscall.Mmap()
is just a thin wrapper over C mmap(2)
so it will behave the same. The memory region you get back can be updated by other processes if you've used the syscall.MAP_SHARED
flag (and the other process did too). You don't have to do anything else except remember to call syscall.Munmap()
when you're finished. It's probably a good candidate for defer
ing, depending on what you're doing.
But, if someone is writing to the shared space and growing it beyond the region you mapped, then you'll have to map it again. It doesn't resize itself automatically.
Upvotes: 2