Byte arrays vs memory mapped files

I am working through Distributed Services with Go

…and to be honest for somebody who hasn’t really done systems programming, the log the author is creating is a bit hard to grokk.

That said, I don’t think you have to read this book to be able to understand the gist of my question, which is what are the different use-cases of using byte arrays vs memory mapped files.

In this book he’s using a buffer of byte arrays backed by a file in one place. My understanding is that flushing the buffer writes what’s in memory to the backing file.

In another place he’s using this memory mapped file package to do a similar thing for an index file.

I understand that writing and reading from memory is quicker than disk io, but is my understanding that flushing a buffer to disc and writing a memory mapped file to disc serves the same purpose? If so, why choose one strategy over another?

Memory mapping delegates the responsibility of loading from and saving to the backing store to the OS, perhaps reducing code for complicated caching schemes and improving I/O performance. Memory-mapped file - Wikipedia

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.