David wrote:
Hi all:
I am processing a 3D bitmaps(essentially ~1024 2D bitmaps with a size of 1MB
each).
If I want read large amount of radom data from this series, how could I
buffer the file to get optimized performance? With WinXP pro/512MB memories
and no other big programmes running at the same time.
Cheers
David
Map the whole file into memory (backed up by the OS).
Read the docs for MapViewOfFile API. This will not use
all the RAM of course, but the system will do the paging
for you, what is far more efficient than what you can do
yourself.
This is not a standard C function, and in another operating
systems you may have to use a different approach.
Using standard C functions you can do the same (as Eric
Sossman replied), but it will be less efficient and is not
trivial to develop.
A simpler approach using just fopen would be to allocate 1MB of virtual
memory with malloc(), then read the whole file into it. The system will
do the paging for you in that case. Frequently used pages will be kept
in memory, less frequently used will be eventually be paged out.
jacob