Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it kosher to memory map a file a second time but with a larger size?

In my application, one file on disk is created and memory mapped with an initial size. If I apply a second memory mapping to the file, with a larger size, the file expands to the new size. Windows lets me do this without error but I don't know if it's actually kosher. Are there any problems with a second memory mapping with a larger size?

like image 265
djcouchycouch Avatar asked Nov 10 '22 00:11

djcouchycouch


1 Answers

The CreateFileMapping documentation has this to say:

After a file mapping object is created, the size of the file must not exceed the size of the file mapping object; if it does, not all of the file contents are available for sharing.

This would appear to imply (since no other downsides or prohibitions are mentioned) that the only side effect of mapping a file a second time with a larger size is that the first mapping won't be able to see the whole thing (obviously).

like image 136
nobody Avatar answered Nov 14 '22 22:11

nobody