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.

    评论

报告相同问题?

悬赏问题

  • ¥15 我想在一个软件里添加一个优惠弹窗,应该怎么写代码
  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流