I just wondered whether it is at all possible to use memory mapped files in portable C or C++. I think not because as far as I know no standard recognizes the existence of memory mapped files.
Using memory mappings it is possible to have the same byte at two addresses. Also, I think it is not possible to even use a piece of memory without constructing an object there first (except through char*
). So if we want to treat an existing mapped file as an array of integers that should be undefined behavior.
So what's the situation regarding memory mapped files and the standard?
They do not. Memory mapping is generally offered by operating systems: C and C++ can also run without one. Imposing such availability on the range of platforms the languages target would be very limiting.
Files may also not be supported at all in freestanding environments, let alone memory mapped ones.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With