Live data from Hacker News

Mio – Cross-platform header-only C++11 library for memory-mapped file IO

github.com

1–10 of 79 posts

Re: Mio – Cross-platform header-only C++11 library for memory-mapped file IO

#3
The code seems clean. I'm not sure this is a great idea in practice, though. Generally the only good reason for mapping stuff out of the filesystem is performance, and VM behavior with mmap() varies wildly across systems (and filesystem backends, and drivers if it's a hardware device, and hardware if it's a framebuffer, and...). Frankly on windows this is AFAIK a mostly-unheard-of technique. No one does mapping.

This just isn't really something that can be cleanly abstracted to do what you want it to do, even if you can make the code "look" the same.

But again, it looks like a nice, clean, modern C++ library. Just IMHO misapplied.

Re: Mio – Cross-platform header-only C++11 library for memory-mapped file IO

#4
post #3

The code seems clean. I'm not sure this is a great idea in practice, though. Generally the only good reason for mapping stuff out of the filesystem is performance, and VM behavior with mmap() varies wildly across systems (and filesystem backends, and drivers if it's a hardware device, and hardware if it's a framebuffer, and...). Frankly on windows this is AFAIK a mostly-unheard-of technique. No one does mapping. This…

> Frankly on windows this is AFAIK a mostly-unheard-of technique. No one does mapping.

Just a data point, but we use memory mapping (both with and without names) in our product that runs on Windows.

Re: Mio – Cross-platform header-only C++11 library for memory-mapped file IO

#7
Bit of a plug here. But I used this library in a small side project (C++ publisher-subscriber library) and it worked like a charm. There are a few things you can customize with mmapping but most use cases will do fine with this. Great work.

https://github.com/drali/pubsub

Re: Mio – Cross-platform header-only C++11 library for memory-mapped file IO

#8
Author here. Long time lurker, but made an an account now.

Wow, I did not expect this. I'm really touched. I wrote this as a small utility for my own consumption because I was unsatisfied with the existing selection at the time, so I'm both surprised and delighted to learn that people are finding it useful. Although to be completely frank, I think this library is way too small and insignificant to deserve a spot on HN's front page, but it definitely made my day. So thank you kind stranger who posted it!

Re: Mio – Cross-platform header-only C++11 library for memory-mapped file IO

#9

The name definitely made me think of Rust's mio. On the other hand, `namespace cplusplus` and `mod rust` maybe are disjoint.

I also think Rust's mio is sufficiently behind-the-scenes that the only people who will encounter it will already be well aware of its purpose; typical Rust users will be two levels removed from mio, if they're using it at all. Namespace collisions matter more for end-user software than foundational libraries. :)

Re: Mio – Cross-platform header-only C++11 library for memory-mapped file IO

#10
I wish people used mmap less.

Creating a new memory mapping can be pretty expensive! On both Windows and Linux, it involves taking a process-wide reader-writer lock in exclusive mode (meaning you get to sit and wait behind page faults), doing a bunch of VMA tree manipulation work, doing various kinds of bookkeeping (hello, rmap!) and then, after you return to userspace, entering the kernel again in response to VM faults just to fill in a few pages by doing, inside the kernel, what amounts to a read (2) anyway!

Sure, if you use mmap, you get to look at the page cache pages directly instead of copying from them into some application-provided buffer, but most of the time, it's not worth the cost.

There are exceptions of course, but you should always default to conventional reads.

Post reply on HN