Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

windows - Pros and Cons of using SetProcessWorkingSetSize

I have an issue with memory management in my application. The application memory is growing up rapidly during the runtime. I'm using datasets in the disconnected mode. To overcome this issue, I'm flushing the DS frequently and also using SetProcessWorkingSetSize to manage the memory usage. It's working fine in my development computer. What are the pros and cons of using SetProcessWorkingSetSize?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

SetProcessWorkingSetSize() controls the amount of RAM that your process uses, it doesn't otherwise have any affect on the virtual memory size of your process. Windows is already quite good at dynamically controlling this, swapping memory pages out on demand when another process needs RAM. By doing this manually, you slow down your program a lot, causing a lot of page faults when Windows is forced to swap the memory pages back in. SetProcessWorkingSetSize is typically used to increase the amount of RAM allocated for a process. Or to force a trim when the app knows that it is going to be idle for a long time. Also done automatically by old Windows versions when you minimize the main window of the app.

No need to pinvoke this btw, you can use the Process.GetCurrentProcess.Min/MaxWorkingSet properties.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...