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 mmapand it doesn't appear to forbid this kind of usage. - Windows: I checked the Windows API. The API devides the task into two functions,
CreateFileMappingandMapViewOfFile. The latter is similar tommap, and wants a handle that is returned by the former. But the size passed toMapViewOfFileis restricted to whatever size was given toCreateFileMapping! Can I simply callCreateFileMappingwith whatever my max file size is going to be, let's say100TBand 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.
Subsequently I found an answer. I would like to quote my comments made to YangXiaoPo-MSFT's answer who was kind enough to provide me with first-hand MSFT information, after which I did some research on my own.
The mentioned answer about
NtExtendSectionis at https://stackoverflow.com/a/55068177/34509 .I also uttered the following