Is there a Threshold for “Out of Memory” error?

拥有回忆 提交于 2019-12-12 20:48:01

问题


When I use some code like,

 x = randi(100,[1000 1000000]);

I get the Out of Memory error.

However when I have,

x = randi(100,[1000 500000]);

I don't get any error but my laptop almost stops working!

and that sometimes costs me a force shutdown.

I would really prefer the Out of Memory error!

Q1+Q2: Is there a threshold for that error, which I could adjust?

Q3: Or any other suggestions (maybe limit the memory that MATLAB can have access)?

Thanks,


回答1:


A1: Yes, the Memory is the Treshold

While the Memory is a limit, your observation of "almost stops working" is related to the CPU-bound processing associated with a task to calculate value for all 500,000,000 elements and get 'em stored. As you can see in A3 this attempt takes 4GB RAM storage to handle just the x.

A2: Yes. Add more Memory to adjust the Treshold

If your problem requires larger objects, get more space to store it, if your CPU-bound observation matters, go get the computation from distributed processing ( be it a Cloud or a Grid ) to off-load your localhost.

A3: Yes. Check MATLAB memory consumed using whos

mCloud:1> x = randi( 100, [1000 500000] );
mCloud:2> whos
Variables in the current scope:

   Attr Name        Size                     Bytes  Class
   ==== ====        ====                     =====  =====
        ans         1x70                       757  cell
        x        1000x500000            4000000000  double

Total is 500000070 elements using 4000000757 bytes

mCloud:3>  


来源:https://stackoverflow.com/questions/26691520/is-there-a-threshold-for-out-of-memory-error

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