not a C++ person here but is header-only library an advantage?
Mio – Cross-platform header-only C++11 library for memory-mapped file IO
31–40 of 79 posts
Re: Mio – Cross-platform header-only C++11 library for memory-mapped file IO
#32Author 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 H…
I like and took a look at the github. I think there is actually a missed opportunity here to make it a single header library since there seem to only be 4 or 5 files that go into it.
Re: Mio – Cross-platform header-only C++11 library for memory-mapped file IO
#33not a C++ person here but is header-only library an advantage?
The disadvantage (and the reason that I'm personally not a fan) is that they bloat compile time. If it's a library you compile it once, and then it gets linked repeatedly, but a header only library is compiled every time any CPP file that includes it is compiled.
Re: Mio – Cross-platform header-only C++11 library for memory-mapped file IO
#34Re: Mio – Cross-platform header-only C++11 library for memory-mapped file IO
#35I 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 fau…
Another problem with mmap is that there is no good way to handle I/O errors. The application will get a signal (SIGSEGV/SIGBUS, can't remember), and no information about what the problem could possibly be. Most applications do not catch these signals and will instead just terminate. Even if you do catch the signal there is a real challenge to know what caused the signal and to keep consistent book-keeping to be able…
Re: Mio – Cross-platform header-only C++11 library for memory-mapped file IO
#36not a C++ person here but is header-only library an advantage?
Re: Mio – Cross-platform header-only C++11 library for memory-mapped file IO
#37I 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 fau…
I <3 mmap
Re: Mio – Cross-platform header-only C++11 library for memory-mapped file IO
#38Earlier quoted context omitted.
This is a valid point. My use case was very frequent reads of large files at pretty much unpredictable positions, so in theory mmap seemed justified. However, I never got around thoroughly testing this assumption, and may indeed just have been better off using read(2) and its variants. You seem very experienced, so I hope you don't mind a question. In my use case the files were as large as tens of gigabytes and I was…
Random access to large files is a legitimate use case! LMDB [1] uses a similar technique, and it works well for them. But depending on the specific application, explicitly application-managed caching via O_DIRECT IO with something like threaded pread or AIO might be even better, because with this explicit model, you control the cache sizing and eviction policy, and it's certainly possible with application-level knowl…
Re: Mio – Cross-platform header-only C++11 library for memory-mapped file IO
#39The 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…
Re: Mio – Cross-platform header-only C++11 library for memory-mapped file IO
#40https://www.boost.org/doc/libs/1_68_0/libs/iostreams/doc/cla...