George2 wrote:
Hello everyone,
I have several physical file and I want to use file map
(MapViewOfFileEx) to map the file into memory to improve performance.
Each file is about several hundred M bytes. All the memory mapped
files are kept open during my application.
The mapping is successful, but the strange thing is,
1. the performance to access the files which are opened at first is
very fast;
2. the performance to access the files which are opened later is
slower and slower (the performance to access the 10th file is very
bad).
Any ideas to improve performance?
It sounds like you are running into disk swapping and/or thrashing issues.
Physical memory is limited (1GB 2GB is common) and is shared amoung
programs, the operating system, etc... As you request memory from the OS it
allocates the memory. :The more memory you request the more that gets
swapped to disk.
So basically what it sounds like is happening, you load a file into memory,
and keep loading files. The memory starts to get swapped to disk. As you
go back and read the memory the OS has to read it from the disk swap file
and write other memory to the swap file for what it's replacing. So now
instead of saving time from reading a file once, it has to write and read.
Several hundred MB of many files is too much to keep in physical memory at
one time. I'm thinking it may actually be faster to read the files as
needed counting on the OS's own file buffering to reduce physical disk I/O.
--
Jim Langston
ta*******@rocketmail.com