Rust, mmap, x86_64 linux

  1. I’m on x86_64 linux. I’m looking to use mmap with Rust.

  2. I have a rough idea of how mmap works, but do not understand any of the details.

  3. Is there a good tutorial that explains on using mmap with Rust?

There isn’t a particular problem I want to solve – I just want to learn how to use in detail.



mmap can be used for a wide variety of reasons; as a specialized memory allocator to creating shared memory for IPC, to faster and/or more convenient fs file reads/writes, so it is a big space and hard to guess where you should start.

Check out the memmap crate. Last I knew, some improvements to the API rustdoc had never been released, so you might possibly want to look at the linked (github repository) source code.

On this forum there was also: How unsafe is mmap?

1 Like


mmap() is a concept of the unix, not Rust. As it’s low level as syscall, using mmap in Rust is not that much different than in C. You may need to understand mmap itself first.



What’s a good resource for mastering mmap? The API seems simple enough, but I suspect there are lots of edge cases.