[英]In python, bash, or perl, how can I artificially inflate my memory
Hopefull really simple. Hopefull真的很简单。 I want to artifically inflate my memory... i'm doing this for testing purposes... Any way in linux would be fine.
我想人为地夸大我的记忆......我这样做是出于测试目的......在linux中的任何方式都没关系。
Python: 蟒蛇:
x = [0]
while True: x.extend(x)
This will double the size of x
until memory runs out (you get MemoryError
). 这将使
x
的大小加倍,直到内存耗尽(你得到MemoryError
)。
Just make a string. 只要做一个字符串。 There are only a few extra bytes overhead, and very fast because the memory is all allocated at once
只有几个额外的字节开销,而且速度非常快,因为内存全部都是一次性分配的
dummy = ' '*num_bytes_to_use_up
There's no portable way to ask how much free memory there is 没有可移植的方式来询问有多少可用内存
under linux you can look at/parse /proc/meminfo
在linux下你可以查看/ parse
/proc/meminfo
>>> open('/proc/meminfo').readlines()[1]
'MemFree: 1248940 kB\n'
>>> dummy = ' '*1000000000
>>> open('/proc/meminfo').readlines()[1]
'MemFree: 271472 kB\n'
>>> del dummy
>>> open('/proc/meminfo').readlines()[1]
'MemFree: 1243464 kB\n'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.