Matlab中“out of memory”的問題總是相當讓人頭疼,比如大矩陣做運算時,一不小心就出現了。
出現該問題的原因在於:內存在使用過程中,經過不斷的分配和釋放過程,導致被分割成許多不連續的區域(即內部或外部碎片)。而Matlab中的矩陣是以塊(block)的形式存儲的,也就是說當Matlab在爲即將存儲的矩陣劃分block時,如果沒有相應大小的連續內存可供分配,就會報告“out of memory”的錯誤。
這也解釋了,爲什麼Matlab剛啓動的時候,要比反覆運行程序一段時間,出現out-of-Memory錯誤的可能性要低。
memory查看內存使用情況
(Memory函數當前僅可用於PCWIN和PCWIN64,即32位和64位Windows操作系統。)
memory指令用於展示Matlab當前正在使用和可用內存的大小(memory displays information showing how much memory is available and how much the MATLAB® software is currently using.):
>> memory
- Maximum Possible Array // 連續空閒內存塊的大小,MATLAB當前能夠創建的單個數組的上界【the size of the largest contiguous free memory block.As such, it is an upper bound on the largest single array MATLAB can create at this time】.
該值的計算:取MATLAB虛擬地址空間的最大連續內存塊和全部可用系統內存中的較小值。 - Memory Available for All Arrays //可用於存儲變量的最大內存大小【Memory Av