0

We have a data processing engine that uses reference data that is mapped into memory when first opened using CreateFile and CreateFileMapping from the Windows API. This results in the data being cached for each portion of the file that is read, and the cache persists until the system is restarted or needs the memory for something else (even if the application is closed and reopened). We periodically install updated reference data, and I've been trying to determine if simply overwriting the reference file with a new version will invalidate the cache or if the system must be restarted.

I've tried searching here and elsewhere (including MS documentation) and have yet to find a definitive answer. I hoping someone has some idea. Thanks.

  • 1
    you can not overwrite file on which section exist. you got error on call CreateFile (`STATUS_USER_MAPPED_FILE` error or `STATUS_SHARING_VIOLATION` (depend from file/section options)) – RbMm Sep 25 '19 at 21:01
  • Considering unmap and remap the file when there is update data. Or use [SEC_NOCACHE](https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createfilemappinga)? – Rita Han Sep 26 '19 at 05:39
  • @RitaHan-MSFT - how `SEC_NOCACHE` can help ? we anyway got `STATUS_USER_MAPPED_FILE` if try overwrite file with section mapped (even wit `SEC_NOCACHE` – RbMm Sep 26 '19 at 08:03
  • @RbMm Of course overwrite is no success. SEC_NOCACHE is used to solve the initial "data being cached" issue. – Rita Han Sep 26 '19 at 09:16
  • Overwriting the file which has an open memory map is not the issue. I can close all the files and exit the application. Then run again and open the files, and they are still mapped in memory. The question is, given that the files are mapped in memory even when not opened by any app, does copying a new version of a file with the same name invalidate the data mapped in memory, or does it get out of sync? – Terry Lawhon Sep 27 '19 at 16:44
  • I believe I now have an answer, although only from doing some testing. It appears that Windows (10 at least) will invalidate memory mapped data from files which are overwritten by either installing or simply copying newer files over existing mapped files. – Terry Lawhon Sep 27 '19 at 19:45

0 Answers0