TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Discovering and exploring mmap using Go

107 pointsby brunoacover 4 years ago

4 comments

EdSchoutenover 4 years ago
For people doing memory mapping in Go, I would strongly advise calling debug.SetPanicOnFault() and setting up a panic handler. Without it, your program will simply crash in case of I&#x2F;O failures, file truncation, etc..<p>Here&#x27;s some code I wrote some time ago that does exactly this:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;buildbarn&#x2F;bb-storage&#x2F;blob&#x2F;c346ca331930f1bc5e4f9bde75de96ee3e6c8a9c&#x2F;pkg&#x2F;blockdevice&#x2F;memory_mapped_block_device_unix.go#L46-L55" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;buildbarn&#x2F;bb-storage&#x2F;blob&#x2F;c346ca331930f1b...</a>
Matthias247over 4 years ago
Be aware that using mmap instead of read&#x2F;write might mess up Go’s scheduling. The runtime has special handling of other blocking system calls which tried to minimize the impact of those on other running goroutines. With directly accessing memory locations mapped via mmap you won’t get this benefit.
slashvar2701over 4 years ago
This kind of articles, sounds like a reminder that system programming is a fundamental knowledge for software engineers.
评论 #25727119 未加载
tedunangstover 4 years ago
Does this assume the file fits in address space? That&#x27;s not always the case.
评论 #25727046 未加载
评论 #25723811 未加载
评论 #25728140 未加载
评论 #25726793 未加载