c++ - Which one is faster, reading from disk or allocate system memory -
My environment is XP 32-bit. I think the allocated memory is almost the maximum size, 2 GB, that means a little bit. Virtual space is available, allocation new memory is very slow.
So if I have a page file, then my app needs to be analyzed by them. I have two ways one has to read them all in system memory, then analyze it as a second cache to reserve the memory buffer first, and read the part of the page file in that buffer, analyze it and then discard it , Then reads the second part of the page file, and overrides the cache, redo the analysis
From profiling, it seems that the second one is faster, because it's time to allocate Costs avoided.
What do you think? Thanks in Advance
(1) I'm not sure the question matches the title. If you are allocating about 32bit Windows 2 GB RAM, then the system is probably putting a lot of storage on the disk, and this is where I want to look first to slow down. When you are using too much memory, you should consider it as disk on stored (in pagefile.sys) but in the physical RAM cached second, allocation Due to the cost of doing so may not be fast, but due to the cost of using a lot of memory at a time, when you copy the file into a larger allocation, you can do this through disk-> disk Too many copies, then When you run it again to analyze it, then you are loading the copy back on the RAM if your analysis is a single-pass algorithm that works a lot of redundancy.
(2) What do I think, mmap files (MapViewOfFile and friends on Windows).
Edit: (3) A Caution If the file is currently 1.8 GB, then maybe there is a chance that next year it will be 4 GB. If so, now I want to plan that its 32 bit machine should have a size greater than 2 ^ 32, which means either taking our second option, or still using MapViewOfFile, but it The file is part of a sensible size of time, instead of all, otherwise you will repeat this code for the first time, when someone first tries a large file and reports the bug.