How do I limit RAM to test low memory situations?

我与影子孤独终老i 提交于 2019-12-12 08:48:34

问题


I'm trying to reproduce a bug that seems to appear when a user is using up a bunch of RAM. What's the best way to either limit the available RAM the computer can use, or fill most of it up? I'd prefer to do this without physically removing memory and without running a bunch of arbitrary, memory-intensive programs (ie, Photoshop, Quake, etc).


回答1:


Use a virtual machine and set resource limits on it to emulate the conditions that you want.

VMWare is one of the leaders in this area and they have a free vmware player that lets you do this.




回答2:


I'm copying my answer from a similar question:

If you are testing a native/unmanaged/C++ application you can use AppVerifier and it's Low Resource Simulation setting which will use fault injection to simulate errors in memory allocations (among many other things). It's also really useful for finding a ton of other subtle problems that often lead to application crashes.

You can also use consume.exe, which is part of the Microsoft Windows SDK for Windows 7 and .NET Framework 3.5 Service Pack 1 to easily use a lot of memory, disk space, cpu time, the page file, or kernel pool and see how your application handles the lack of available resources. (Does it crash? How is the performance affected? etc.)




回答3:


Use either a job object or ulimit(1).




回答4:


Create a virtual machine and set the ram to what you need.

The one I use is Virtual Box from SUN.

http://www.virtualbox.org/

It is easy to set up.




回答5:


If you are developing in Java, you can set the memory limits for the JVM at startup.



来源:https://stackoverflow.com/questions/2285701/how-do-i-limit-ram-to-test-low-memory-situations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!