How to asynchronously clear a memory mapped file?

I use memory mapped files to have read / write access to a large number of image files (~ 10000 x 16 MB) under Windows 7 64 bit. My goals:

  • Having as much data as possible.

  • The ability to highlight new images and record them as quickly as possible.

Therefore, I use memory mapped files to access files. Caching works well, but the OS does not clear dirty pages until I almost got out of physical memory. Because of this, the allocation and writing to new files occurs rather slowly after the physical memory is full.

One solution would be to use FlushViewOfFiles() regularly, but this function does not return until data is written to disk.

Is there a way to clear file association asynchronously? The only solution I found was again Unmap() and MapViewOfFile() , but using this approach, I cannot be sure to get the same data pointer again. Can anyone suggest a better approach?

Edit: After reading the WINAPI documentation several times, I found a suitable solution for my problem:

Calling VirtualUnlock() on a memory range that is not locked results in the loss of dirty pages.

+8
c ++ memory-mapped-files
source share
1 answer

I heard that the FlushViewOfFile () function does NOT wait until it physically writes to a file.

http://msdn.microsoft.com/en-us/library/windows/desktop/aa366563(v=vs.85).aspx

The FlushViewOfFile function does not clear the file metadata, and it does not wait for a return until the changes are flushed from the main cache of the hardware disk and physically written to the disk.

After calling "FlushFileBuffers (...)" your data will be physically written to disk.

+2
source share

All Articles