Is it possible in Windows and Linux to mmap chunks of memory on a file that isn't as large as the mapping?
The file may contain only a few bytes worth of values, but I want to create multiple 1MB (in that ballpark) memory-mapping and read from this memory as the file grows. The file is written-to by the same program. I will never touch memory beyond the end of the file. But I don't want to redo the mmap calls with every new values that are appended into the file!
- Linux: I checked
man 2 mmap
and it doesn't appear to forbid this kind of usage. - Windows: I checked the Windows API. The API devides the task into two functions,
CreateFileMapping
andMapViewOfFile
. The latter is similar tommap
, and wants a handle that is returned by the former. But the size passed toMapViewOfFile
is restricted to whatever size was given toCreateFileMapping
! Can I simply callCreateFileMapping
with whatever my max file size is going to be, let's say100TB
and Windows will let me create views of the file as the file grows till100TB
?
I checked folly's MemoryMap implementation, and it won't allow mappings larger than the file size. Neither does python's mmap. I haven't found a definitive answer for boost.interprocess.