Naveen
2010-11-30 10:19:58 UTC
I have a application where I use memory mapping to load the images. It
creates a temporary file using CreateFile() with CREATE_ALWAYS and
FILE_FLAG_DELETE_ON_CLOSE|FILE_ATTRIBUTE_TEMPORARY flags. Then it
creates a file mapping object using CreateFileMapping() and then maps
the memory using MapViewOfFile(). After mapping the view, it writes
some data into this region and unmaps the view of the file using
UnmapViewOfFile() (File mapping handle is not closed at this point and
will be closed at a later point of time). The problem is when I repeat
this process for about 7000 times the available RAM (checked using
perfmon) goes very low (I am running on 4GB RAM machine, available
physical memory goes to ~4MB). Because of this the system becomes
unusable. So it looks like OS is keeping the dirty pages in RAM only
even after unmapping. To solve this I tried using FlushViewOfFile(),
although it helps the performance of the system becomes very bad. For
example, if previouslt it took 50 seconds to map/unmap the 7000 images
with FlushViewOfFile it takes 100 seconds. Is there any way to solve
this problem (i.e. somehow remove my pages from RAM so that system
becomes responsive)? Also, does it make any difference if I run this
on Vista/Windows 7?
creates a temporary file using CreateFile() with CREATE_ALWAYS and
FILE_FLAG_DELETE_ON_CLOSE|FILE_ATTRIBUTE_TEMPORARY flags. Then it
creates a file mapping object using CreateFileMapping() and then maps
the memory using MapViewOfFile(). After mapping the view, it writes
some data into this region and unmaps the view of the file using
UnmapViewOfFile() (File mapping handle is not closed at this point and
will be closed at a later point of time). The problem is when I repeat
this process for about 7000 times the available RAM (checked using
perfmon) goes very low (I am running on 4GB RAM machine, available
physical memory goes to ~4MB). Because of this the system becomes
unusable. So it looks like OS is keeping the dirty pages in RAM only
even after unmapping. To solve this I tried using FlushViewOfFile(),
although it helps the performance of the system becomes very bad. For
example, if previouslt it took 50 seconds to map/unmap the 7000 images
with FlushViewOfFile it takes 100 seconds. Is there any way to solve
this problem (i.e. somehow remove my pages from RAM so that system
becomes responsive)? Also, does it make any difference if I run this
on Vista/Windows 7?