Just for experiment, and Fun...
I am trying to create an app that can "Purposely" consume RAM as much as we specify immediately.
e.g. I want to consume 512 MB RAM, then the app will consume 512 MB directly.
I have search on the web, most of them are using while loop to fill the ram with variable or data. But I think it is slow way to fill the RAM and might not accurate either.
I am looking for a library in python about memory management. and came across these http://docs.python.org/library/mmap.html. But can't figure out how to use these library to eat the RAM Space in one shot.
I ever saw an mem-eater application, but don't know how they were written...
So, is there any other better suggestion for Fill the RAM with random data immediately?
Or Should I just use while loop to fill the data manually but with Multi-Threading to make it faster?
解决方案
One simple way might be:
some_str = ' ' * 512000000
Seemed to work pretty well in my tests.
Edit: in Python 3, you might want to use bytearray(512000000) instead.