// JP opened flex table

Click to See Complete Forum and Search --> : Memory Size II


lt_w
November 22nd, 2000, 02:22 PM
I have a mathematical application project in Visual C++ for a research at school. Sometimes the project needs to locate large memory space by "malloc()" functions. My machine has 128M memory. For some reason, the memory (fault) swap is kicked in after 26M of the memory is allocated by the system. Then it is extremely slow. I add another 128M RAM to the machine, and then it pushes the limit to 55M. But my project eventually will require 200M space (even more).

Microsoft people told me to use function "setprocessworkingsetsize" to set the physical memory size. For that, I have to install Window 2000. The function "setprocessworkingsetsize" works up to 136M. But the problem stays. When I use the memory more than 55 M (with 256M main memory), the memory swap begins just like before under Window 98.

I have more than enough main memory space. And what I really need is to set the physical memory size (or working set) to avoid the memory swap. Any suggestion?

Thanks for the attention.

nikb
November 22nd, 2000, 02:37 PM
Hello again,

I will reiterate what I told you in your previous posting, which you apparently chose to ignore, and I'll try to give you some more hints on how to go about trying to minimize swapping.

However, before I do that, I would like to note, that if you had taken the time to read the MSDN help page on "SetProcessWorkingSetSize" you would have seen what Microsoft recommends for the issue you're facing.

But onwards... The spoon is ready, open wide:

There is no "100% sure" way to control how windows swaps your process out, or to prevent it from doing so.

As you have found out SetProcessWorkingSetSize is only available when running on the NT kernel (NT and 2K series) and furthermore, it does not allow you to specify any "physical memory size" and whoever told you that deserves a beating. It allows an application to specify how many pages of virtual memory it wants to be allowed to have before triggering a page fault and initiating swapping. The problem is that the number you specify is just a hint to Windows. It does not have to allow you that many pages, and it does not guarantee that if you get them, you'll get to keep them. Remember, Windows is running other things as well, and they want some of that RAM too!

If you can limit your application to Windows 2000 only, then you can use the function "VirtualLock" to lock ranges of the virtual address space in memory. Be advised however, that it is not recommended you lock all 200MB of your application. Doing so severely undermines the ability of Windows to juggle memory around, and can lead to failure of system operations, such as thread and process creation, and kernel memory pool functions to name a few. You would not want the kernel crashing on you because you gobbled up all the memory, would you?

Be careful when using those... You're playing with matches, and you might get burned!

-n

//JP added flex table