Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does any C or C++ standard recognize the existence of memory mapped files?

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?

like image 880
boot4life Avatar asked Dec 18 '22 18:12

boot4life


1 Answers

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.

like image 143
edmz Avatar answered Dec 24 '22 01:12

edmz