vimpunk / mio

Cross-platform C++11 header-only library for memory mapped file IO
MIT License
1.71k stars 157 forks source link

Error handling windows (CreateFileMapping) #102

Open DanielHerchenbach opened 1 year ago

DanielHerchenbach commented 1 year ago

Hello, thank you for this library, I found it helpful! A minor issue, the handle in this line: https://github.com/mandreyel/mio/blob/8b6b7d878c89e81614d05edca7936de41ccdd2da/single_include/mio/mio.hpp#L928 should be compared with nullptr to detect the error case in my opinion. https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createfilemappinga#return-value

DanielHerchenbach commented 1 year ago

This bit me when I tried to mmap an empty file. It surprised me that the underlying APIs of the OS usually treat this as an error. Maybe handle this special case internally or leave a comment somewhere in the documentation?