How to Eat Memory using Python?

前端 未结 5 725
无人及你
无人及你 2021-01-31 16:10

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 ap

5条回答
  •  南旧
    南旧 (楼主)
    2021-01-31 16:41

    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.

提交回复
热议问题