duanniubeng2265 2018-07-25 20:09
浏览 277

在Go中读取不断增长的mmap文件

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?

  • 写回答

1条回答

  • doushi7394 2018-07-25 20:48
    关注

    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 defering, 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.

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料