简体   繁体   中英

In python, bash, or perl, how can I artificially inflate my memory

Hopefull really simple. I want to artifically inflate my memory... i'm doing this for testing purposes... Any way in linux would be fine.

Python:

x = [0]
while True: x.extend(x)

This will double the size of x until memory runs out (you get 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

>>> 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'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM